X-Git-Url: http://andersk.mit.edu/gitweb/gssapi-openssh.git/blobdiff_plain/9cb1827beb97ef775b73d81402cc084ec8c316a3..d76f17672018832a885e3ce6087123d85bda0bca:/openssh/openbsd-compat/realpath.c diff --git a/openssh/openbsd-compat/realpath.c b/openssh/openbsd-compat/realpath.c index 77da14e..ec801d4 100644 --- a/openssh/openbsd-compat/realpath.c +++ b/openssh/openbsd-compat/realpath.c @@ -13,9 +13,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -35,7 +32,7 @@ #if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: realpath.c,v 1.10 2003/08/01 21:04:59 millert Exp $"; +static char *rcsid = "$OpenBSD: realpath.c,v 1.5 2001/06/27 00:58:56 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -65,22 +62,18 @@ char * realpath(const char *path, char *resolved) { struct stat sb; - int fd, n, needslash, serrno = 0; + int fd, n, rootd, serrno = 0; char *p, *q, wbuf[MAXPATHLEN], start[MAXPATHLEN]; int symlinks = 0; /* Save the starting point. */ getcwd(start,MAXPATHLEN); if ((fd = open(".", O_RDONLY)) < 0) { - (void)strlcpy(resolved, ".", MAXPATHLEN); + (void)strcpy(resolved, "."); return (NULL); } close(fd); - /* Convert "." -> "" to optimize away a needless lstat() and chdir() */ - if (path[0] == '.' && path[1] == '\0') - path = ""; - /* * Find the dirname and basename from the path to be resolved. * Change directory to the dirname component. @@ -109,7 +102,7 @@ loop: p = resolved; /* Deal with the last component. */ - if (*p != '\0' && lstat(p, &sb) == 0) { + if (lstat(p, &sb) == 0) { if (S_ISLNK(sb.st_mode)) { if (++symlinks > MAXSYMLINKS) { serrno = ELOOP; @@ -132,7 +125,7 @@ loop: * Save the last component name and get the full pathname of * the current directory. */ - (void)strlcpy(wbuf, p, sizeof wbuf); + (void)strcpy(wbuf, p); if (getcwd(resolved, MAXPATHLEN) == 0) goto err1; @@ -141,18 +134,18 @@ loop: * happens if the last component is empty, or the dirname is root. */ if (resolved[0] == '/' && resolved[1] == '\0') - needslash = 0; + rootd = 1; else - needslash = 1; + rootd = 0; if (*wbuf) { - if (strlen(resolved) + strlen(wbuf) + needslash >= MAXPATHLEN) { + if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) { serrno = ENAMETOOLONG; goto err1; } - if (needslash == 0) - strlcat(resolved, "/", MAXPATHLEN); - strlcat(resolved, wbuf, MAXPATHLEN); + if (rootd == 0) + (void)strcat(resolved, "/"); + (void)strcat(resolved, wbuf); } /* Go back to where we came from. */