X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=builtins%2Fcd.def;h=4bbad7e15cb8218b96f50728c54b4e1e01ce56b3;hb=d166f048818e10cf3799aa24a174fb22835f1acc;hp=e6611d0d7fc96f548731e1dfbdb33df0e012e3e6;hpb=ccc6cda312fea9f0468ee65b8f368e9653e1380b;p=platform%2Fupstream%2Fbash.git diff --git a/builtins/cd.def b/builtins/cd.def index e6611d0..4bbad7e 100644 --- a/builtins/cd.def +++ b/builtins/cd.def @@ -49,13 +49,16 @@ extern int errno; #endif /* !errno */ extern int posixly_correct, interactive; +extern int array_needs_making; extern char *bash_getcwd_errstr; static int change_to_directory (); static char *cdspell (); static int spname (), mindist (), spdist (); -int cdspelling = 1; + +/* Change this to 1 to get cd spelling correction by default. */ +int cdspelling = 0; int cdable_vars; @@ -118,8 +121,9 @@ static int bindpwd (no_symlinks) int no_symlinks; { - char *dirname; - int old_symlinks; + char *dirname, *pwdvar; + int old_symlinks, old_anm; + SHELL_VAR *tvar; if (no_symlinks) { @@ -132,7 +136,22 @@ bindpwd (no_symlinks) dirname = get_working_directory ("cd"); bind_variable ("OLDPWD", get_string_value ("PWD")); - bind_variable ("PWD", dirname); + + old_anm = array_needs_making; + tvar = bind_variable ("PWD", dirname); + /* This is an efficiency hack. If PWD is exported, we will need to + remake the exported environment every time we change directories. + If there is no other reason to make the exported environment, just + update PWD in place and mark the exported environment as no longer + needing a remake. */ + if (old_anm == 0 && array_needs_making && exported_p (tvar)) + { + pwdvar = xmalloc (strlen (dirname) + 5); /* 5 = "PWD" + '=' + '\0' */ + strcpy (pwdvar, "PWD="); + strcpy (pwdvar + 4, dirname); + add_or_supercede_exported_var (pwdvar, 0); + array_needs_making = 0; + } FREE (dirname); return (EXECUTION_SUCCESS); @@ -547,6 +566,9 @@ mindist(dir, guess, best) } (void)closedir(fd); + /* Don't return `.' */ + if (best[0] == '.' && best[1] == '\0') + dist = 3; return dist; }