diff options
Diffstat (limited to 'contrib/binutils/libiberty/getcwd.c')
-rw-r--r-- | contrib/binutils/libiberty/getcwd.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/contrib/binutils/libiberty/getcwd.c b/contrib/binutils/libiberty/getcwd.c index 60c1dd8..47b1c1e 100644 --- a/contrib/binutils/libiberty/getcwd.c +++ b/contrib/binutils/libiberty/getcwd.c @@ -14,13 +14,18 @@ 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> @@ -46,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; |