diff options
author | jilles <jilles@FreeBSD.org> | 2016-01-24 17:01:34 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2016-01-24 17:01:34 +0000 |
commit | 78c5210bf8bd29d8c4626741191c10dd7ab1a1a4 (patch) | |
tree | c5377c050d3d617b9d0fed9561b6c571c44ac484 | |
parent | 6cdde1eb9e112d83ff4d63a31ab8e0762f564e0d (diff) | |
download | FreeBSD-src-78c5210bf8bd29d8c4626741191c10dd7ab1a1a4.zip FreeBSD-src-78c5210bf8bd29d8c4626741191c10dd7ab1a1a4.tar.gz |
sh: Remove a global variable from cd.c.
-rw-r--r-- | bin/sh/cd.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/bin/sh/cd.c b/bin/sh/cd.c index aa2549f..d034896 100644 --- a/bin/sh/cd.c +++ b/bin/sh/cd.c @@ -68,14 +68,13 @@ __FBSDID("$FreeBSD$"); static int cdlogical(char *); static int cdphysical(char *); static int docd(char *, int, int); -static char *getcomponent(void); +static char *getcomponent(char **); static char *findcwd(char *); static void updatepwd(char *); static char *getpwd(void); static char *getpwd2(void); static char *curdir = NULL; /* current working directory */ -static char *cdcomppath; int cdcmd(int argc __unused, char **argv __unused) @@ -177,6 +176,7 @@ cdlogical(char *dest) char *p; char *q; char *component; + char *path; struct stat statb; int first; int badstat; @@ -187,14 +187,14 @@ cdlogical(char *dest) * next time we get the value of the current directory. */ badstat = 0; - cdcomppath = stsavestr(dest); + path = stsavestr(dest); STARTSTACKSTR(p); if (*dest == '/') { STPUTC('/', p); - cdcomppath++; + path++; } first = 1; - while ((q = getcomponent()) != NULL) { + while ((q = getcomponent(&path)) != NULL) { if (q[0] == '\0' || (q[0] == '.' && q[1] == '\0')) continue; if (! first) @@ -243,25 +243,25 @@ cdphysical(char *dest) } /* - * Get the next component of the path name pointed to by cdcomppath. - * This routine overwrites the string pointed to by cdcomppath. + * Get the next component of the path name pointed to by *path. + * This routine overwrites *path and the string pointed to by it. */ static char * -getcomponent(void) +getcomponent(char **path) { char *p; char *start; - if ((p = cdcomppath) == NULL) + if ((p = *path) == NULL) return NULL; - start = cdcomppath; + start = *path; while (*p != '/' && *p != '\0') p++; if (*p == '\0') { - cdcomppath = NULL; + *path = NULL; } else { *p++ = '\0'; - cdcomppath = p; + *path = p; } return start; } @@ -272,6 +272,7 @@ findcwd(char *dir) { char *new; char *p; + char *path; /* * If our argument is NULL, we don't know the current directory @@ -280,14 +281,14 @@ findcwd(char *dir) */ if (dir == NULL || curdir == NULL) return getpwd2(); - cdcomppath = stsavestr(dir); + path = stsavestr(dir); STARTSTACKSTR(new); if (*dir != '/') { STPUTS(curdir, new); if (STTOPC(new) == '/') STUNPUTC(new); } - while ((p = getcomponent()) != NULL) { + while ((p = getcomponent(&path)) != NULL) { if (equal(p, "..")) { while (new > stackblock() && (STUNPUTC(new), *new) != '/'); } else if (*p != '\0' && ! equal(p, ".")) { |