Commit d05ba220 by Melissa O'Neill Committed by Jeff Law

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
parent 71cce721
...@@ -14,6 +14,9 @@ DESCRIPTION ...@@ -14,6 +14,9 @@ DESCRIPTION
current directory's path doesn't fit in LEN characters, the result current directory's path doesn't fit in LEN characters, the result
is NULL and errno is set. is NULL and errno is set.
If pathname is a null pointer, getcwd() will obtain size bytes of
space using malloc.
BUGS BUGS
Emulated via the getwd() call, which is reasonable for most Emulated via the getwd() call, which is reasonable for most
systems that do not have getcwd(). systems that do not have getcwd().
...@@ -48,6 +51,13 @@ getcwd (buf, len) ...@@ -48,6 +51,13 @@ getcwd (buf, len)
errno = ERANGE; errno = ERANGE;
return 0; return 0;
} }
if (!buf) {
buf = (char*)malloc(len);
if (!buf) {
errno = ENOMEM;
return 0;
}
}
strcpy (buf, ourbuf); strcpy (buf, ourbuf);
} }
return buf; return buf;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment