diff options
author | Melissa O'Neill <oneill@cs.sfu.ca> | 1999-05-25 21:04:27 -0600 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 1999-05-25 21:04:27 -0600 |
commit | d05ba2205fc7af481d806eab41773f970ad305cf (patch) | |
tree | 6822279f8afade103f7210691eba8da4d1507573 /libiberty/getcwd.c | |
parent | 71cce721af1a8d2e5f9c9508982c35996cdd940e (diff) | |
download | gcc-d05ba2205fc7af481d806eab41773f970ad305cf.zip gcc-d05ba2205fc7af481d806eab41773f970ad305cf.tar.gz gcc-d05ba2205fc7af481d806eab41773f970ad305cf.tar.bz2 |
getcwd.c (getcwd): If pathname is NULL, then obtain SIZE bytes of space using malloc.
P
* getcwd.c (getcwd): If pathname is NULL, then obtain SIZE
bytes of space using malloc.
From-SVN: r27161
Diffstat (limited to 'libiberty/getcwd.c')
-rw-r--r-- | libiberty/getcwd.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/libiberty/getcwd.c b/libiberty/getcwd.c index 06d55c0..47b1c1e 100644 --- a/libiberty/getcwd.c +++ b/libiberty/getcwd.c @@ -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; |