From: Melissa O'Neill Date: Wed, 26 May 1999 03:04:27 +0000 (-0600) Subject: getcwd.c (getcwd): If pathname is NULL, then obtain SIZE bytes of space using malloc. X-Git-Tag: releases/libgcj-2.95.0~365 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d05ba2205fc7af481d806eab41773f970ad305cf;p=thirdparty%2Fgcc.git 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 --- diff --git a/libiberty/getcwd.c b/libiberty/getcwd.c index 06d55c04f586..47b1c1eec31e 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;