X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/6e37afca0fac31fb9da11a0227562ac83939e86a..8f9189bebe2f5c60b92328ab7def4b5b2642d7e1:/usr/src/bin/csh/dir.c diff --git a/usr/src/bin/csh/dir.c b/usr/src/bin/csh/dir.c index 79d809fa8e..9907f2502c 100644 --- a/usr/src/bin/csh/dir.c +++ b/usr/src/bin/csh/dir.c @@ -6,21 +6,34 @@ */ #ifndef lint -static char sccsid[] = "@(#)dir.c 5.6 (Berkeley) %G%"; +static char sccsid[] = "@(#)dir.c 5.12 (Berkeley) %G%"; #endif /* not lint */ -#include "sh.h" -#include "sh.dir.h" -/* - * C Shell - directory management - */ - -static struct directory *dfind(); -static Char *dfollow(); -static void printdirs(); -static Char *dgoto(); -static void dnewcwd(); -static void dset(); +#include +#include +#include +#include +#include +#include +#if __STDC__ +# include +#else +# include +#endif + +#include "csh.h" +#include "dir.h" +#include "extern.h" + +/* Directory management. */ + +static struct directory + *dfind __P((Char *)); +static Char *dfollow __P((Char *)); +static void printdirs __P((void)); +static Char *dgoto __P((Char *)); +static void dnewcwd __P((struct directory *)); +static void dset __P((Char *)); struct directory dhead; /* "head" of loop */ int printd; /* force name to be printed */ @@ -48,13 +61,13 @@ dinit(hp) tcp = short2str(hp); (void) xprintf(emsg, tcp); if (chdir(tcp) == -1) - cp = (Char *) 0; + cp = NULL; else cp = hp; } else - cp = (Char *) 0; - if (cp == (Char *) 0) { + cp = NULL; + if (cp == NULL) { (void) xprintf(emsg, "/"); if (chdir("/") == -1) /* I am not even try to print an error message! */ @@ -378,6 +391,7 @@ dfollow(cp) register Char *dp; struct varent *c; char ebuf[MAXPATHLEN]; + int serrno; cp = globone(cp, G_ERROR); /* @@ -392,6 +406,7 @@ dfollow(cp) xfree((ptr_t) dp); if (chdir(short2str(cp)) >= 0) return dgoto(cp); + serrno = errno; } if (cp[0] != '/' && !prefix(STRdotsl, cp) && !prefix(STRdotdotsl, cp) @@ -421,7 +436,7 @@ dfollow(cp) } (void) strcpy(ebuf, short2str(cp)); xfree((ptr_t) cp); - stderror(ERR_SYSTEM, ebuf, strerror(errno)); + stderror(ERR_SYSTEM, ebuf, strerror(serrno)); return (NULL); } @@ -594,7 +609,7 @@ dcanon(cp, p) Char tmpdir[MAXPATHLEN]; p1 = value(STRcwd); - if (p1 == (Char *) 0 || *p1 != '/') + if (p1 == NULL || *p1 != '/') abort(); if (Strlen(p1) + Strlen(cp) + 1 >= MAXPATHLEN) abort(); @@ -797,11 +812,11 @@ dcanon(cp, p) /* * See if we're not in a subdir of STRhome */ - if (p1 && *p1 && + if (p1 && *p1 == '/' && (Strncmp(p1, cp, cc) != 0 || (cp[cc] != '/' && cp[cc] != '\0'))) { static ino_t home_ino = -1; static dev_t home_dev = -1; - static Char *home_ptr = (Char *) 0; + static Char *home_ptr = NULL; struct stat statbuf; /* @@ -817,7 +832,7 @@ dcanon(cp, p) * Start comparing dev & ino backwards */ p2 = Strcpy(link, cp); - for (sp = (Char *) 0; *p2 && stat(short2str(p2), &statbuf) != -1;) { + for (sp = NULL; *p2 && stat(short2str(p2), &statbuf) != -1;) { if (statbuf.st_dev == home_dev && statbuf.st_ino == home_ino) { sp = (Char *) - 1; @@ -829,7 +844,7 @@ dcanon(cp, p) /* * See if we found it */ - if (*p2 && sp == (Char *) - 1) { + if (*p2 && sp == (Char *) -1) { /* * Use STRhome to make '~' work */