Makefile.in (CFILES): Add calloc.c and getpwd.c.

* Makefile.in (CFILES): Add calloc.c and getpwd.c.
	(REQUIRED_OFILES): Add getpwd.o.
	(getpwd.o): Add target.

	* configure.in (AC_PREREQ): Bump to 2.13.
	(AC_CHECK_HEADERS): Add check for <sys/stat.h>.

	* getpwd.c: New file, moved here from gcc.

From-SVN: r28996
This commit is contained in:
Kaveh R. Ghazi 1999-08-31 00:50:36 +00:00 committed by Kaveh Ghazi
parent 00d30284b8
commit 4ac3cb830a
6 changed files with 138 additions and 6 deletions

View File

@ -1,3 +1,14 @@
1999-08-30 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* Makefile.in (CFILES): Add calloc.c and getpwd.c.
(REQUIRED_OFILES): Add getpwd.o.
(getpwd.o): Add target.
* configure.in (AC_PREREQ): Bump to 2.13.
(AC_CHECK_HEADERS): Add check for <sys/stat.h>.
* getpwd.c: New file, moved here from gcc.
1999-08-25 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* cplus-dem.c (gnu_special): Cast a `size_t' to `long' when

View File

@ -121,8 +121,8 @@ HFILES = alloca-conf.h
# (alphabetical), and add them to REQUIRED_OFILES or funcs in
# configure.in.
CFILES = asprintf.c alloca.c argv.c atexit.c basename.c bcmp.c bcopy.c \
bzero.c choose-temp.c clock.c concat.c cplus-dem.c fdmatch.c \
fnmatch.c getcwd.c getopt.c getopt1.c getpagesize.c \
bzero.c calloc.c choose-temp.c clock.c concat.c cplus-dem.c fdmatch.c \
fnmatch.c getcwd.c getpwd.c getopt.c getopt1.c getpagesize.c \
getruntime.c floatformat.c hex.c index.c insque.c memchr.c \
memcmp.c memcpy.c memmove.c memset.c mkstemps.c objalloc.c obstack.c \
pexecute.c putenv.c random.c rename.c rindex.c setenv.c sigsetmask.c \
@ -133,7 +133,7 @@ CFILES = asprintf.c alloca.c argv.c atexit.c basename.c bcmp.c bcopy.c \
# These are always included in the library.
REQUIRED_OFILES = argv.o choose-temp.o concat.o cplus-dem.o \
fdmatch.o fnmatch.o getopt.o getopt1.o getruntime.o hex.o \
fdmatch.o fnmatch.o getopt.o getopt1.o getpwd.o getruntime.o hex.o \
floatformat.o objalloc.o obstack.o pexecute.o spaces.o \
splay-tree.o strerror.o strsignal.o xatexit.o xexit.o xmalloc.o \
xstrdup.o xstrerror.o
@ -254,6 +254,7 @@ getcwd.o: config.h
getopt.o: config.h $(INCDIR)/getopt.h
getopt1.o: config.h $(INCDIR)/getopt.h
getpagesize.o: config.h
getpwd.o: config.h $(INCDIR)/libiberty.h
getruntime.o: config.h $(INCDIR)/libiberty.h
hex.o: $(INCDIR)/libiberty.h
floatformat.o: $(INCDIR)/floatformat.h

View File

@ -214,6 +214,9 @@
/* Define if you have the <sys/resource.h> header file. */
#undef HAVE_SYS_RESOURCE_H
/* Define if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H

2
libiberty/configure vendored
View File

@ -1055,7 +1055,7 @@ else
fi
echo "$ac_t""$CPP" 1>&6
for ac_hdr in sys/file.h sys/param.h stdlib.h string.h unistd.h strings.h sys/time.h sys/resource.h
for ac_hdr in sys/file.h sys/param.h stdlib.h string.h unistd.h strings.h sys/time.h sys/resource.h sys/stat.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6

View File

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script
AC_PREREQ(2.12.1)
AC_PREREQ(2.13)
AC_INIT(pexecute.c)
dnl We use these options to decide which functions to include.
@ -106,7 +106,7 @@ AC_SUBST_FILE(host_makefile_frag)
# It's OK to check for header files. Although the compiler may not be
# able to link anything, it had better be able to at least compile
# something.
AC_CHECK_HEADERS(sys/file.h sys/param.h stdlib.h string.h unistd.h strings.h sys/time.h sys/resource.h)
AC_CHECK_HEADERS(sys/file.h sys/param.h stdlib.h string.h unistd.h strings.h sys/time.h sys/resource.h sys/stat.h)
AC_HEADER_SYS_WAIT
# This is the list of functions which libiberty will provide if they

117
libiberty/getpwd.c Normal file
View File

@ -0,0 +1,117 @@
/* getpwd.c - get the working directory */
#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. */
#if !(defined (POSIX) || defined (USG) || defined (VMS)) || defined (HAVE_GETWD)
#define getcwd(buf,len) getwd(buf)
#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__)))
/* 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__ */