X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=libiberty%2Fgetpwd.c;h=fa5c132fd6b6e48c11efe723dfc492635ddc1522;hb=28ce7b07473c33f2e4e380a861973d68ffe8017f;hp=de6e03976483fcb86ac3f5c9cff86245cdb246d4;hpb=e2eaf477991014a67bc122c3225f6a3fe6d1a8e6;p=deliverable%2Fbinutils-gdb.git diff --git a/libiberty/getpwd.c b/libiberty/getpwd.c index de6e039764..fa5c132fd6 100644 --- a/libiberty/getpwd.c +++ b/libiberty/getpwd.c @@ -1,5 +1,17 @@ /* getpwd.c - get the working directory */ +/* + +@deftypefn Supplemental char* getpwd (void) + +Returns the current working directory. This implementation caches the +result on the assumption that the process will not call @code{chdir} +between calls to @code{getpwd}. + +@end deftypefn + +*/ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -23,10 +35,9 @@ extern int errno; #if HAVE_SYS_STAT_H #include #endif - -/* Prototype these in case the system headers don't provide them. */ -extern char *getpwd (); -extern char *getwd (); +#if HAVE_LIMITS_H +#include +#endif #include "libiberty.h" @@ -35,6 +46,8 @@ extern char *getwd (); the few exceptions to the general rule here. */ #if !defined(HAVE_GETCWD) && defined(HAVE_GETWD) +/* Prototype in case the system headers doesn't provide it. */ +extern char *getwd (); #define getcwd(buf,len) getwd(buf) #endif @@ -52,7 +65,7 @@ extern char *getwd (); yield 0 and set errno. */ char * -getpwd () +getpwd (void) { static char *pwd; static int failure_errno; @@ -71,7 +84,7 @@ getpwd () && dotstat.st_dev == pwdstat.st_dev)) /* The shortcut didn't work. Try the slow, ``sure'' way. */ - for (s = GUESSPATHLEN; ! getcwd (p = xmalloc (s), s); s *= 2) + for (s = GUESSPATHLEN; !getcwd (p = XNEWVEC (char, s), s); s *= 2) { int e = errno; free (p); @@ -99,12 +112,12 @@ getpwd () #endif char * -getpwd () +getpwd (void) { static char *pwd = 0; if (!pwd) - pwd = getcwd (xmalloc (MAXPATHLEN + 1), MAXPATHLEN + 1 + pwd = getcwd (XNEWVEC (char, MAXPATHLEN + 1), MAXPATHLEN + 1 #ifdef VMS , 0 #endif