Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/gen Use __getcwd() system call in getcwd() unless O...



details:   https://anonhg.NetBSD.org/src/rev/0df831ea951f
branches:  trunk
changeset: 467581:0df831ea951f
user:      sommerfe <sommerfe%NetBSD.org@localhost>
date:      Fri Mar 26 04:04:13 1999 +0000

description:
Use __getcwd() system call in getcwd() unless OLD_GETCWD is defined

diffstat:

 lib/libc/gen/getcwd.c |  49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 2 deletions(-)

diffs (74 lines):

diff -r eaaaa3de7cc7 -r 0df831ea951f lib/libc/gen/getcwd.c
--- a/lib/libc/gen/getcwd.c     Fri Mar 26 03:40:41 1999 +0000
+++ b/lib/libc/gen/getcwd.c     Fri Mar 26 04:04:13 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getcwd.c,v 1.15 1998/11/06 19:43:23 christos Exp $     */
+/*     $NetBSD: getcwd.c,v 1.16 1999/03/26 04:04:13 sommerfe 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.15 1998/11/06 19:43:23 christos Exp $");
+__RCSID("$NetBSD: getcwd.c,v 1.16 1999/03/26 04:04:13 sommerfe Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -186,6 +186,8 @@
        return (NULL);
 }
 
+#ifdef OLD_GETCWD
+
 char *
 getcwd(pt, size)
        char *pt;
@@ -377,3 +379,46 @@
        free(up);
        return (NULL);
 }
+
+#else /* New getcwd */
+
+char *
+getcwd(pt, size)
+       char *pt;
+       size_t size;
+{
+       int ptsize, bufsize, len;
+       
+       /*
+        * If no buffer specified by the user, allocate one as necessary.
+        * If a buffer is specified, the size has to be non-zero.  The path
+        * is built from the end of the buffer backwards.
+        */
+       if (pt) {
+               ptsize = 0;
+               if (!size) {
+                       errno = EINVAL;
+                       return (NULL);
+               }
+               bufsize = size;
+       } else {
+               if ((pt = malloc(ptsize = 1024 - 4)) == NULL)
+                       return (NULL);
+               bufsize = ptsize;
+       }
+       do {
+               len = __getcwd(pt, bufsize);
+               if ((len < 0) && (size == 0) && (errno == ERANGE)) {
+                       if ((pt = realloc(pt, ptsize *= 2)) == NULL)
+                               return NULL;
+                       bufsize = ptsize;
+                       continue;
+               }
+       } while (0);
+       if (len < 0)
+               return NULL;
+       else
+               return pt;
+}
+
+#endif



Home | Main Index | Thread Index | Old Index