]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
getcwd.c (getcwd): If pathname is NULL, then obtain SIZE bytes of space using malloc.
authorMelissa O'Neill <oneill@cs.sfu.ca>
Wed, 26 May 1999 03:04:27 +0000 (21:04 -0600)
committerJeff Law <law@gcc.gnu.org>
Wed, 26 May 1999 03:04:27 +0000 (21:04 -0600)
P
        * getcwd.c (getcwd): If pathname is NULL, then obtain SIZE
        bytes of space using malloc.

From-SVN: r27161

libiberty/getcwd.c

index 06d55c04f58699752e91909fef0e69ed2ede726f..47b1c1eec31e1c680bbb5deb42efb07e84f6a3f6 100644 (file)
@@ -14,6 +14,9 @@ DESCRIPTION
        current directory's path doesn't fit in LEN characters, the result
        is NULL and errno is set.
 
+       If pathname is a null pointer, getcwd() will obtain size bytes of
+       space using malloc.
+
 BUGS
        Emulated via the getwd() call, which is reasonable for most
        systems that do not have getcwd().
@@ -48,6 +51,13 @@ getcwd (buf, len)
       errno = ERANGE;
       return 0;
     }
+    if (!buf) {
+       buf = (char*)malloc(len);
+       if (!buf) {
+           errno = ENOMEM;
+          return 0;
+       }
+    }
     strcpy (buf, ourbuf);
   }
   return buf;