sh: Remove a global variable from cd.c.
This commit is contained in:
parent
6cdde1eb9e
commit
78c5210bf8
29
bin/sh/cd.c
29
bin/sh/cd.c
@ -68,14 +68,13 @@ __FBSDID("$FreeBSD$");
|
|||||||
static int cdlogical(char *);
|
static int cdlogical(char *);
|
||||||
static int cdphysical(char *);
|
static int cdphysical(char *);
|
||||||
static int docd(char *, int, int);
|
static int docd(char *, int, int);
|
||||||
static char *getcomponent(void);
|
static char *getcomponent(char **);
|
||||||
static char *findcwd(char *);
|
static char *findcwd(char *);
|
||||||
static void updatepwd(char *);
|
static void updatepwd(char *);
|
||||||
static char *getpwd(void);
|
static char *getpwd(void);
|
||||||
static char *getpwd2(void);
|
static char *getpwd2(void);
|
||||||
|
|
||||||
static char *curdir = NULL; /* current working directory */
|
static char *curdir = NULL; /* current working directory */
|
||||||
static char *cdcomppath;
|
|
||||||
|
|
||||||
int
|
int
|
||||||
cdcmd(int argc __unused, char **argv __unused)
|
cdcmd(int argc __unused, char **argv __unused)
|
||||||
@ -177,6 +176,7 @@ cdlogical(char *dest)
|
|||||||
char *p;
|
char *p;
|
||||||
char *q;
|
char *q;
|
||||||
char *component;
|
char *component;
|
||||||
|
char *path;
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
int first;
|
int first;
|
||||||
int badstat;
|
int badstat;
|
||||||
@ -187,14 +187,14 @@ cdlogical(char *dest)
|
|||||||
* next time we get the value of the current directory.
|
* next time we get the value of the current directory.
|
||||||
*/
|
*/
|
||||||
badstat = 0;
|
badstat = 0;
|
||||||
cdcomppath = stsavestr(dest);
|
path = stsavestr(dest);
|
||||||
STARTSTACKSTR(p);
|
STARTSTACKSTR(p);
|
||||||
if (*dest == '/') {
|
if (*dest == '/') {
|
||||||
STPUTC('/', p);
|
STPUTC('/', p);
|
||||||
cdcomppath++;
|
path++;
|
||||||
}
|
}
|
||||||
first = 1;
|
first = 1;
|
||||||
while ((q = getcomponent()) != NULL) {
|
while ((q = getcomponent(&path)) != NULL) {
|
||||||
if (q[0] == '\0' || (q[0] == '.' && q[1] == '\0'))
|
if (q[0] == '\0' || (q[0] == '.' && q[1] == '\0'))
|
||||||
continue;
|
continue;
|
||||||
if (! first)
|
if (! first)
|
||||||
@ -243,25 +243,25 @@ cdphysical(char *dest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the next component of the path name pointed to by cdcomppath.
|
* Get the next component of the path name pointed to by *path.
|
||||||
* This routine overwrites the string pointed to by cdcomppath.
|
* This routine overwrites *path and the string pointed to by it.
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
getcomponent(void)
|
getcomponent(char **path)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
char *start;
|
char *start;
|
||||||
|
|
||||||
if ((p = cdcomppath) == NULL)
|
if ((p = *path) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
start = cdcomppath;
|
start = *path;
|
||||||
while (*p != '/' && *p != '\0')
|
while (*p != '/' && *p != '\0')
|
||||||
p++;
|
p++;
|
||||||
if (*p == '\0') {
|
if (*p == '\0') {
|
||||||
cdcomppath = NULL;
|
*path = NULL;
|
||||||
} else {
|
} else {
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
cdcomppath = p;
|
*path = p;
|
||||||
}
|
}
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
@ -272,6 +272,7 @@ findcwd(char *dir)
|
|||||||
{
|
{
|
||||||
char *new;
|
char *new;
|
||||||
char *p;
|
char *p;
|
||||||
|
char *path;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If our argument is NULL, we don't know the current directory
|
* If our argument is NULL, we don't know the current directory
|
||||||
@ -280,14 +281,14 @@ findcwd(char *dir)
|
|||||||
*/
|
*/
|
||||||
if (dir == NULL || curdir == NULL)
|
if (dir == NULL || curdir == NULL)
|
||||||
return getpwd2();
|
return getpwd2();
|
||||||
cdcomppath = stsavestr(dir);
|
path = stsavestr(dir);
|
||||||
STARTSTACKSTR(new);
|
STARTSTACKSTR(new);
|
||||||
if (*dir != '/') {
|
if (*dir != '/') {
|
||||||
STPUTS(curdir, new);
|
STPUTS(curdir, new);
|
||||||
if (STTOPC(new) == '/')
|
if (STTOPC(new) == '/')
|
||||||
STUNPUTC(new);
|
STUNPUTC(new);
|
||||||
}
|
}
|
||||||
while ((p = getcomponent()) != NULL) {
|
while ((p = getcomponent(&path)) != NULL) {
|
||||||
if (equal(p, "..")) {
|
if (equal(p, "..")) {
|
||||||
while (new > stackblock() && (STUNPUTC(new), *new) != '/');
|
while (new > stackblock() && (STUNPUTC(new), *new) != '/');
|
||||||
} else if (*p != '\0' && ! equal(p, ".")) {
|
} else if (*p != '\0' && ! equal(p, ".")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user