]> andersk Git - gssapi-openssh.git/blobdiff - openssh/openbsd-compat/realpath.c
Quotes and white space cleanup.
[gssapi-openssh.git] / openssh / openbsd-compat / realpath.c
index 77da14e7c246d570bb8c1dacfc4d6686dc992db9..ec801d498dc9d21b82d05a5ec54760df7c293b74 100644 (file)
@@ -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 <sys/param.h>
@@ -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. */
This page took 0.137287 seconds and 4 git commands to generate.