OSDN Git Service

* parse.y (check_static_final_variable_assignment_flag): Fix spelling.
[pf3gnuchains/gcc-fork.git] / libiberty / getcwd.c
index 60c1dd8..3445563 100644 (file)
@@ -14,16 +14,27 @@ 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().
 
 */
 
-#ifndef NO_SYS_PARAM_H
+#include "config.h"
+
+#ifdef HAVE_SYS_PARAM_H
 #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;
@@ -46,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;