[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.3.4.1 and 1.5

version 1.3.4.1, 1995/05/02 19:34:46 version 1.5, 1995/06/16 07:05:30
Line 1 
Line 1 
   /*      $NetBSD$        */
   
 /*  /*
  * Copyright (c) 1989, 1991 The Regents of the University of California.   * Copyright (c) 1989, 1991, 1993
  * All rights reserved.   *      The Regents of the University of California.  All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions   * modification, are permitted provided that the following conditions
Line 32 
Line 34 
  */   */
   
 #if defined(LIBC_SCCS) && !defined(lint)  #if defined(LIBC_SCCS) && !defined(lint)
 /*static char *sccsid = "from: @(#)getcwd.c     5.11 (Berkeley) 2/24/91";*/  #if 0
 static char *rcsid = "$Id$";  static char sccsid[] = "@(#)getcwd.c    8.1 (Berkeley) 6/4/93";
   #else
   static char rcsid[] = "$NetBSD$";
   #endif
 #endif /* LIBC_SCCS and not lint */  #endif /* LIBC_SCCS and not lint */
   
 #include "namespace.h"  
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/stat.h>  #include <sys/stat.h>
   
 #include <errno.h>  #include <errno.h>
 #include <dirent.h>  #include <dirent.h>
 #include <stdio.h>  #include <stdio.h>
Line 77  getcwd(pt, size)
Line 82  getcwd(pt, size)
                 ptsize = 0;                  ptsize = 0;
                 if (!size) {                  if (!size) {
                         errno = EINVAL;                          errno = EINVAL;
                         return((char *)NULL);                          return (NULL);
                 }                  }
                 ept = pt + size;                  ept = pt + size;
         } else {          } else {
                 if (!(pt = (char *)malloc(ptsize = 1024 - 4)))                  if ((pt = malloc(ptsize = 1024 - 4)) == NULL)
                         return((char *)NULL);                          return (NULL);
                 ept = pt + ptsize;                  ept = pt + ptsize;
         }          }
         bpt = ept - 1;          bpt = ept - 1;
Line 93  getcwd(pt, size)
Line 98  getcwd(pt, size)
          * 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 = (char *)malloc(upsize = 1024 - 4)))          if ((up = malloc(upsize = 1024 - 4)) == NULL)
                 goto err;                  goto err;
         eup = up + MAXPATHLEN;          eup = up + MAXPATHLEN;
         bup = up;          bup = up;
Line 125  getcwd(pt, size)
Line 130  getcwd(pt, size)
                          * path to the beginning of the buffer, but it's always                           * path to the beginning of the buffer, but it's always
                          * been that way and stuff would probably break.                           * been that way and stuff would probably break.
                          */                           */
                         (void)bcopy(bpt, pt, ept - bpt);                          bcopy(bpt, pt, ept - bpt);
                         free(up);                          free(up);
                         return(pt);                          return (pt);
                 }                  }
   
                 /*                  /*
Line 136  getcwd(pt, size)
Line 141  getcwd(pt, size)
                  * 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 = (char *)realloc(up, upsize *= 2)))                          if ((up = realloc(up, upsize *= 2)) == NULL)
                                 goto err;                                  goto err;
                           bup = up;
                         eup = up + upsize;                          eup = up + upsize;
                 }                  }
                 *bup++ = '.';                  *bup++ = '.';
Line 196  getcwd(pt, size)
Line 202  getcwd(pt, size)
                         }                          }
                         off = bpt - pt;                          off = bpt - pt;
                         len = ept - bpt;                          len = ept - bpt;
                         if (!(pt = (char *)realloc(pt, ptsize *= 2)))                          if ((pt = realloc(pt, ptsize *= 2)) == NULL)
                                 goto err;                                  goto err;
                         bpt = pt + off;                          bpt = pt + off;
                         ept = pt + ptsize;                          ept = pt + ptsize;
                         (void)bcopy(bpt, ept - len, len);                          bcopy(bpt, ept - len, len);
                         bpt = ept - len;                          bpt = ept - len;
                 }                  }
                 if (!first)                  if (!first)
Line 226  err:
Line 232  err:
         if (ptsize)          if (ptsize)
                 free(pt);                  free(pt);
         free(up);          free(up);
         return((char *)NULL);          return (NULL);
 }  }

Legend:
Removed from v.1.3.4.1  
changed lines
  Added in v.1.5

CVSweb <webmaster@jp.NetBSD.org>