Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/gen/getcwd.c,v retrieving revision 1.8 retrieving revision 1.14 diff -u -p -r1.8 -r1.14 --- src/lib/libc/gen/getcwd.c 1998/02/02 02:41:23 1.8 +++ src/lib/libc/gen/getcwd.c 1998/08/26 00:38:40 1.14 @@ -1,4 +1,4 @@ -/* $NetBSD: getcwd.c,v 1.8 1998/02/02 02:41:23 perry Exp $ */ +/* $NetBSD: getcwd.c,v 1.14 1998/08/26 00:38:40 perry Exp $ */ /* * Copyright (c) 1989, 1991, 1993, 1995 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)getcwd.c 8.5 (Berkeley) 2/7/95"; #else -__RCSID("$NetBSD: getcwd.c,v 1.8 1998/02/02 02:41:23 perry Exp $"); +__RCSID("$NetBSD: getcwd.c,v 1.14 1998/08/26 00:38:40 perry Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -59,46 +59,13 @@ __RCSID("$NetBSD: getcwd.c,v 1.8 1998/02 #ifdef __weak_alias __weak_alias(getcwd,_getcwd); +__weak_alias(realpath,_realpath); #endif -static char *getcwd_physical __P((char *, size_t)); - #define ISDOT(dp) \ (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) -char * -getcwd(pt, size) - char *pt; - size_t size; -{ - char *pwd; - size_t pwdlen; - dev_t dev; - ino_t ino; - struct stat s; - - /* Check $PWD -- if it's right, it's fast. */ - if ((pwd = getenv("PWD")) != NULL && pwd[0] == '/' && !stat(pwd, &s)) { - dev = s.st_dev; - ino = s.st_ino; - if (!stat(".", &s) && dev == s.st_dev && ino == s.st_ino) { - pwdlen = strlen(pwd); - if (size != 0) { - if (pwdlen + 1 > size) { - errno = ERANGE; - return (NULL); - } - } else if ((pt = malloc(pwdlen + 1)) == NULL) - return (NULL); - memmove(pt, pwd, pwdlen); - pt[pwdlen] = '\0'; - return (pt); - } - } - - return (getcwd_physical(pt, size)); -} /* * char *realpath(const char *path, char resolved_path[MAXPATHLEN]); @@ -170,13 +137,13 @@ loop: * Save the last component name and get the full pathname of * the current directory. */ - (void)strcpy(wbuf, p); + (void)strncpy(wbuf, p, (sizeof(wbuf) - 1)); /* * Call the inernal internal version of getcwd which * does a physical search rather than using the $PWD short-cut */ - if (getcwd_physical(resolved, MAXPATHLEN) == 0) + if (getcwd(resolved, MAXPATHLEN) == 0) goto err1; /* @@ -194,8 +161,8 @@ loop: goto err1; } if (rootd == 0) - (void)strcat(resolved, "/"); - (void)strcat(resolved, wbuf); + (void)strcat(resolved, "/"); /* XXX: strcat is safe */ + (void)strcat(resolved, wbuf); /* XXX: strcat is safe */ } /* Go back to where we came from. */ @@ -215,17 +182,17 @@ err2: (void)close(fd); return (NULL); } -static char * -getcwd_physical(pt, size) +char * +getcwd(pt, size) char *pt; size_t size; { - register struct dirent *dp; - register DIR *dir; - register dev_t dev; - register ino_t ino; - register int first; - register char *bpt, *bup; + struct dirent *dp; + DIR *dir; + dev_t dev; + ino_t ino; + int first; + char *bpt, *bup; struct stat s; dev_t root_dev; ino_t root_ino; @@ -290,7 +257,7 @@ getcwd_physical(pt, size) * path to the beginning of the buffer, but it's always * been that way and stuff would probably break. */ - bcopy(bpt, pt, ept - bpt); + memmove(pt, bpt, (size_t)(ept - bpt)); free(up); return (pt); } @@ -336,7 +303,8 @@ getcwd_physical(pt, size) goto notfound; if (ISDOT(dp)) continue; - bcopy(dp->d_name, bup, dp->d_namlen + 1); + memmove(bup, dp->d_name, + (size_t)(dp->d_namlen + 1)); /* Save the first error for later. */ if (lstat(up, &s)) { @@ -366,13 +334,13 @@ getcwd_physical(pt, size) goto err; bpt = pt + off; ept = pt + ptsize; - bcopy(bpt, ept - len, len); + memmove(ept - len, bpt, len); bpt = ept - len; } if (!first) *--bpt = '/'; bpt -= dp->d_namlen; - bcopy(dp->d_name, bpt, dp->d_namlen); + memmove(bpt, dp->d_name, (size_t)dp->d_namlen); (void)closedir(dir); /* Truncate any file name. */