* coff-rs6000.c: Add missing prototypes.
[deliverable/binutils-gdb.git] / libiberty / getcwd.c
index 06d55c04f58699752e91909fef0e69ed2ede726f..344556392b31c0fab62f2c859392b0211d48581e 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().
@@ -26,6 +29,12 @@ BUGS
 #include <sys/param.h>
 #endif
 #include <errno.h>
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
 
 extern char *getwd ();
 extern int errno;
@@ -48,6 +57,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;
This page took 0.023386 seconds and 4 git commands to generate.