[BACK]Return to getcwd.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / gen

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/lib/libc/gen/getcwd.c between version 1.25.2.1 and 1.33

version 1.25.2.1, 2003/08/04 04:25:26 version 1.33, 2005/01/06 00:07:41
Line 15 
Line 15 
  * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software   * 3. Neither the name of the University nor the names of its contributors
  *    must display the following acknowledgement:  
  *      This product includes software developed by the University of  
  *      California, Berkeley and its contributors.  
  * 4. Neither the name of the University nor the names of its contributors  
  *    may be used to endorse or promote products derived from this software   *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.   *    without specific prior written permission.
  *   *
Line 95  realpath(path, resolved)
Line 91  realpath(path, resolved)
   
         /* Save the starting point. */          /* Save the starting point. */
         if ((fd = open(".", O_RDONLY)) < 0) {          if ((fd = open(".", O_RDONLY)) < 0) {
                 (void)strcpy(resolved, ".");                  (void)strlcpy(resolved, ".", MAXPATHLEN);
                 return (NULL);                  return (NULL);
         }          }
   
Line 107  realpath(path, resolved)
Line 103  realpath(path, resolved)
          *     if it is a directory, then change to that directory.           *     if it is a directory, then change to that directory.
          * get the current directory name and append the basename.           * get the current directory name and append the basename.
          */           */
         (void)strncpy(resolved, path, MAXPATHLEN - 1);          if (strlcpy(resolved, path, MAXPATHLEN) >= MAXPATHLEN) {
         resolved[MAXPATHLEN - 1] = '\0';                  errno = ENAMETOOLONG;
                   goto err1;
           }
 loop:  loop:
         q = strrchr(resolved, '/');          q = strrchr(resolved, '/');
         if (q != NULL) {          if (q != NULL) {
Line 134  loop:
Line 132  loop:
                                 errno = ELOOP;                                  errno = ELOOP;
                                 goto err1;                                  goto err1;
                         }                          }
                         n = readlink(p, resolved, MAXPATHLEN);                          n = readlink(p, resolved, MAXPATHLEN-1);
                         if (n < 0)                          if (n < 0)
                                 goto err1;                                  goto err1;
                         resolved[n] = '\0';                          resolved[n] = '\0';
Line 151  loop:
Line 149  loop:
          * Save the last component name and get the full pathname of           * Save the last component name and get the full pathname of
          * the current directory.           * the current directory.
          */           */
         (void)strlcpy(wbuf, p, sizeof(wbuf));          if (strlcpy(wbuf, p, sizeof(wbuf)) >= sizeof(wbuf)) {
                   errno = ENAMETOOLONG;
                   goto err1;
           }
   
         /*          /*
          * Call the inernal internal version of getcwd which           * Call the inernal internal version of getcwd which
Line 176  loop:
Line 177  loop:
                         goto err1;                          goto err1;
                 }                  }
                 if (rootd == 0)                  if (rootd == 0)
                         (void)strcat(resolved, "/"); /* XXX: strcat is safe */                          if (strlcat(resolved, "/", MAXPATHLEN) >= MAXPATHLEN) {
                 (void)strcat(resolved, wbuf);   /* XXX: strcat is safe */                                  errno = ENAMETOOLONG;
                                   goto err1;
                           }
                   if (strlcat(resolved, wbuf, MAXPATHLEN) >= MAXPATHLEN) {
                           errno = ENAMETOOLONG;
                           goto err1;
                   }
         }          }
   
         /* Go back to where we came from. */          /* Go back to where we came from. */
Line 215  getcwd(pt, size)
Line 222  getcwd(pt, size)
         ino_t root_ino;          ino_t root_ino;
         size_t ptsize, upsize;          size_t ptsize, upsize;
         int save_errno;          int save_errno;
         char *ept, *eup, *up;          char *ept, *eup, *up, *nup;
         size_t dlen;          size_t dlen;
   
         /*          /*
Line 239  getcwd(pt, size)
Line 246  getcwd(pt, size)
         *bpt = '\0';          *bpt = '\0';
   
         /*          /*
          * Allocate bytes (1024 - malloc space) for the string of "../"'s.           * Allocate bytes for the string of "../"'s.
          * Should always be enough (it's 340 levels).  If it's not, allocate           * Should always be enough (it's 340 levels).  If it's not, allocate
          * as necessary.  Special case the first stat, it's ".", not "..".           * as necessary.  Special case the first stat, it's ".", not "..".
          */           */
         if ((up = malloc(upsize = 1024 - 4)) == NULL)          if ((up = malloc(upsize = MAXPATHLEN)) == NULL)
                 goto err;                  goto err;
         eup = up + MAXPATHLEN;          eup = up + upsize;
         bup = up;          bup = up;
         up[0] = '.';          up[0] = '.';
         up[1] = '\0';          up[1] = '\0';
Line 285  getcwd(pt, size)
Line 292  getcwd(pt, size)
                  * as necessary.  Max length is 3 for "../", the largest                   * as necessary.  Max length is 3 for "../", the largest
                  * possible component name, plus a trailing NULL.                   * possible component name, plus a trailing NULL.
                  */                   */
                 if (bup + 3  + MAXNAMLEN + 1 >= eup) {                  if (bup + 3 + MAXNAMLEN + 1 >= eup) {
                         if ((up = realloc(up, upsize *= 2)) == NULL)                          if ((nup = realloc(up, upsize *= 2)) == NULL)
                                 goto err;                                  goto err;
                         bup = up;                          bup = nup + (buf - up);
                           up = nup;
                         eup = up + upsize;                          eup = up + upsize;
                 }                  }
                 *bup++ = '.';                  *bup++ = '.';

Legend:
Removed from v.1.25.2.1  
changed lines
  Added in v.1.33

CVSweb <webmaster@jp.NetBSD.org>