/* 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
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
-
-/* Prototype these in case the system headers don't provide them. */
-extern char *getpwd ();
-extern char *getwd ();
+#if HAVE_LIMITS_H
+#include <limits.h>
+#endif
#include "libiberty.h"
BSD systems) now provides getcwd as called for by POSIX. Allow for
the few exceptions to the general rule here. */
-#if !(defined (POSIX) || defined (USG) || defined (VMS)) || defined (HAVE_GETWD)
+#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
+
#ifdef MAXPATHLEN
#define GUESSPATHLEN (MAXPATHLEN + 1)
#else
#define GUESSPATHLEN 100
#endif
-#else /* (defined (USG) || defined (VMS)) */
-/* We actually use this as a starting point, not a limit. */
-#define GUESSPATHLEN 100
-#endif /* (defined (USG) || defined (VMS)) */
#if !(defined (VMS) || (defined(_WIN32) && !defined(__CYGWIN__)))
yield 0 and set errno. */
char *
-getpwd ()
+getpwd (void)
{
static char *pwd;
static int failure_errno;
&& 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);
#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