1999-08-31 02:50:36 +02:00
|
|
|
/* getpwd.c - get the working directory */
|
|
|
|
|
configure.in (MAKEINFO, PERL): Detect these.
* configure.in (MAKEINFO, PERL): Detect these.
(--enable-maintainer-mode): Add.
* configure: Regenerate.
* Makefile.in (MAKEINFO, PERL): Define.
(libiberty.info, libiberty.dvi, libiberty.html): New.
(CFILES): Add bsearch.c.
(CONFIGURED_OFILES): New, list of objects configure might add.
(maint-missing, maint-buildall): New, for maintainers only.
(clean, mostlyclean): Add info/dvi/html files.
* libiberty.texi, copying-lib.texi, obstacks.texi, functions.texi: New.
* gather-docs: New, for maintainers.
* maint-tool: New, for maintainers.
* alloca.c, atexit.c, basename.c, bcmp.c, bcopy.c, bsearch.c,
bzero.c, calloc.c, clock.c, configure.in, configure, getcwd.c,
getpagesize.c, getpwd.c, index.c, memchr.c, memcmp.c, memcpy.c,
memmove.c, memset.c, putenv.c, rename.c, rindex.c, setenv.c,
sigsetmask.c, strcasecmp.c, strchr.c, strdup.c, strerror.c,
strncasecmp.c, strncmp.c, strrchr.c, strstr.c, strtod.c, strtol.c,
tmpnam.c, vfork.c, vprintf.c, waitpid.c, xatexit.c, xexit.c,
xmalloc.c, xmemdup.c, xstrdup.c, xstrerror.c: Add or update
documentation.
Co-Authored-By: Phil Edwards <pedwards@disaster.jaj.com>
From-SVN: r45828
2001-09-26 20:16:17 +02:00
|
|
|
/*
|
|
|
|
|
alloca.c, [...]: Improve manual formatting.
* alloca.c, clock.c, getcwd.c, getpagesize.c, getpwd.c, index.c,
libiberty.texi, memchr.c, putenv.c, rindex.c, strchr.c, strdup.c,
strerror.c, strrchr.c, strstr.c, strtod.c, tmpnam.c, vfork.c,
xatexit.c, xmalloc.c, xstrerror.c: Improve manual formatting. Fix
spelling. Give names to function arguments in documentation. Use
(void) prototypes in documentation.
* functions.texi: Regenerate.
From-SVN: r46068
2001-10-07 23:53:31 +02:00
|
|
|
@deftypefn Supplemental char* getpwd (void)
|
configure.in (MAKEINFO, PERL): Detect these.
* configure.in (MAKEINFO, PERL): Detect these.
(--enable-maintainer-mode): Add.
* configure: Regenerate.
* Makefile.in (MAKEINFO, PERL): Define.
(libiberty.info, libiberty.dvi, libiberty.html): New.
(CFILES): Add bsearch.c.
(CONFIGURED_OFILES): New, list of objects configure might add.
(maint-missing, maint-buildall): New, for maintainers only.
(clean, mostlyclean): Add info/dvi/html files.
* libiberty.texi, copying-lib.texi, obstacks.texi, functions.texi: New.
* gather-docs: New, for maintainers.
* maint-tool: New, for maintainers.
* alloca.c, atexit.c, basename.c, bcmp.c, bcopy.c, bsearch.c,
bzero.c, calloc.c, clock.c, configure.in, configure, getcwd.c,
getpagesize.c, getpwd.c, index.c, memchr.c, memcmp.c, memcpy.c,
memmove.c, memset.c, putenv.c, rename.c, rindex.c, setenv.c,
sigsetmask.c, strcasecmp.c, strchr.c, strdup.c, strerror.c,
strncasecmp.c, strncmp.c, strrchr.c, strstr.c, strtod.c, strtol.c,
tmpnam.c, vfork.c, vprintf.c, waitpid.c, xatexit.c, xexit.c,
xmalloc.c, xmemdup.c, xstrdup.c, xstrerror.c: Add or update
documentation.
Co-Authored-By: Phil Edwards <pedwards@disaster.jaj.com>
From-SVN: r45828
2001-09-26 20:16:17 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
1999-08-31 02:50:36 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#ifndef errno
|
|
|
|
extern int errno;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.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 ();
|
|
|
|
|
|
|
|
#include "libiberty.h"
|
|
|
|
|
|
|
|
/* Virtually every UN*X system now in common use (except for pre-4.3-tahoe
|
|
|
|
BSD systems) now provides getcwd as called for by POSIX. Allow for
|
|
|
|
the few exceptions to the general rule here. */
|
|
|
|
|
1999-08-31 22:33:13 +02:00
|
|
|
#if !defined(HAVE_GETCWD) && defined(HAVE_GETWD)
|
1999-08-31 02:50:36 +02:00
|
|
|
#define getcwd(buf,len) getwd(buf)
|
1999-08-31 22:33:13 +02:00
|
|
|
#endif
|
|
|
|
|
1999-08-31 02:50:36 +02:00
|
|
|
#ifdef MAXPATHLEN
|
|
|
|
#define GUESSPATHLEN (MAXPATHLEN + 1)
|
|
|
|
#else
|
|
|
|
#define GUESSPATHLEN 100
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !(defined (VMS) || (defined(_WIN32) && !defined(__CYGWIN__)))
|
|
|
|
|
|
|
|
/* Get the working directory. Use the PWD environment variable if it's
|
|
|
|
set correctly, since this is faster and gives more uniform answers
|
|
|
|
to the user. Yield the working directory if successful; otherwise,
|
|
|
|
yield 0 and set errno. */
|
|
|
|
|
|
|
|
char *
|
|
|
|
getpwd ()
|
|
|
|
{
|
|
|
|
static char *pwd;
|
|
|
|
static int failure_errno;
|
|
|
|
|
|
|
|
char *p = pwd;
|
|
|
|
size_t s;
|
|
|
|
struct stat dotstat, pwdstat;
|
|
|
|
|
|
|
|
if (!p && !(errno = failure_errno))
|
|
|
|
{
|
|
|
|
if (! ((p = getenv ("PWD")) != 0
|
|
|
|
&& *p == '/'
|
|
|
|
&& stat (p, &pwdstat) == 0
|
|
|
|
&& stat (".", &dotstat) == 0
|
|
|
|
&& dotstat.st_ino == pwdstat.st_ino
|
|
|
|
&& 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)
|
|
|
|
{
|
|
|
|
int e = errno;
|
|
|
|
free (p);
|
|
|
|
#ifdef ERANGE
|
|
|
|
if (e != ERANGE)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
errno = failure_errno = e;
|
|
|
|
p = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cache the result. This assumes that the program does
|
|
|
|
not invoke chdir between calls to getpwd. */
|
|
|
|
pwd = p;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* VMS || _WIN32 && !__CYGWIN__ */
|
|
|
|
|
|
|
|
#ifndef MAXPATHLEN
|
|
|
|
#define MAXPATHLEN 255
|
|
|
|
#endif
|
|
|
|
|
|
|
|
char *
|
|
|
|
getpwd ()
|
|
|
|
{
|
|
|
|
static char *pwd = 0;
|
|
|
|
|
|
|
|
if (!pwd)
|
|
|
|
pwd = getcwd (xmalloc (MAXPATHLEN + 1), MAXPATHLEN + 1
|
|
|
|
#ifdef VMS
|
|
|
|
, 0
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
return pwd;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* VMS || _WIN32 && !__CYGWIN__ */
|