Author: jilles
Date: Sun Jan 24 17:01:34 2016
New Revision: 294667
URL: https://svnweb.freebsd.org/changeset/base/294667

Log:
  sh: Remove a global variable from cd.c.

Modified:
  head/bin/sh/cd.c

Modified: head/bin/sh/cd.c
==============================================================================
--- head/bin/sh/cd.c    Sun Jan 24 15:44:57 2016        (r294666)
+++ head/bin/sh/cd.c    Sun Jan 24 17:01:34 2016        (r294667)
@@ -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, ".")) {
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to