This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch to move gcc/getpwd.c to libiberty


	This patch moves gcc/getpwd.c to libiberty/.  It relies on
http://egcs.cygnus.com/ml/egcs-patches/1999-05/msg00647.html to work
properly.

(I bootstrapped on Irix6 as a test.)

	Okay to install?

		--Kaveh


1999-05-27  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* Makefile.in (OBJS, PROTO_OBJS): Remove getpwd.o.
	(getpwd.o): Remove.

	* getpwd.c: Delete file.  Its in libiberty now.

	* dbxout.c (getpwd): Don't prototype.
	* dwarf2out.c (getpwd): Likewise
	* dwarfout.c (getpwd): Likewise
	* final.c (getpwd): Likewise.
	* protoize.c (getpwd): Likewise.

diff -rup egcs-19990524/gcc/Makefile.in test/egcs-19990524/gcc/Makefile.in
--- egcs-19990524/gcc/Makefile.in	Thu May 20 18:26:33 1999
+++ test/egcs-19990524/gcc/Makefile.in	Wed May 26 12:26:40 1999
@@ -677,7 +677,7 @@ OBJS = toplev.o version.o tree.o print-t
  regclass.o regmove.o local-alloc.o global.o reload.o reload1.o caller-save.o \
  insn-peep.o reorg.o $(SCHED_PREFIX)sched.o final.o recog.o reg-stack.o \
  insn-opinit.o insn-recog.o insn-extract.o insn-output.o insn-emit.o lcm.o \
- profile.o insn-attrtab.o $(out_object_file) getpwd.o $(EXTRA_OBJS) convert.o \
+ profile.o insn-attrtab.o $(out_object_file) $(EXTRA_OBJS) convert.o \
  mbchar.o dyn-string.o splay-tree.o graph.o sbitmap.o resource.o hash.o
 
 # GEN files are listed separately, so they can be built before doing parallel
@@ -1504,7 +1504,6 @@ emit-rtl.o : emit-rtl.c $(CONFIG_H) syst
    except.h function.h $(REGS_H) insn-config.h $(RECOG_H) real.h \
    $(EXPR_H) $(srcdir)/../include/obstack.h hard-reg-set.h bitmap.h toplev.h
 real.o : real.c $(CONFIG_H) system.h $(TREE_H) toplev.h
-getpwd.o : getpwd.c $(CONFIG_H) system.h
 
 integrate.o : integrate.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) flags.h \
    integrate.h insn-flags.h insn-config.h $(EXPR_H) real.h $(REGS_H) \
@@ -2006,7 +2005,7 @@ cppinit.o:  cppinit.c $(CONFIG_H) cpplib
 
 proto: config.status protoize$(exeext) unprotoize$(exeext) SYSCALLS.c.X
 
-PROTO_OBJS = getpwd.o intl.o version.o 
+PROTO_OBJS = intl.o version.o 
 
 protoize$(exeext): protoize.o $(PROTO_OBJS) $(LIBDEPS)
 	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ protoize.o $(PROTO_OBJS) $(LIBS)
diff -rup egcs-19990524/gcc/dbxout.c test/egcs-19990524/gcc/dbxout.c
--- egcs-19990524/gcc/dbxout.c	Sun Apr 18 09:09:24 1999
+++ test/egcs-19990524/gcc/dbxout.c	Wed May 26 12:14:26 1999
@@ -136,8 +136,6 @@ Boston, MA 02111-1307, USA.  */
 #endif
 #endif
 
-char *getpwd ();
-
 /* Typical USG systems don't have stab.h, and they also have
    no use for DBX-format debugging info.  */
 
diff -rup egcs-19990524/gcc/dwarf2out.c test/egcs-19990524/gcc/dwarf2out.c
--- egcs-19990524/gcc/dwarf2out.c	Sun Apr 18 09:09:25 1999
+++ test/egcs-19990524/gcc/dwarf2out.c	Wed May 26 12:14:47 1999
@@ -2021,8 +2021,6 @@ dwarf2out_frame_finish ()
 /* And now, the support for symbolic debugging information.  */
 #ifdef DWARF2_DEBUGGING_INFO
 
-extern char *getpwd PROTO((void));
-
 /* NOTE: In the comments in this file, many references are made to
    "Debugging Information Entries".  This term is abbreviated as `DIE'
    throughout the remainder of this file.  */
diff -rup egcs-19990524/gcc/dwarfout.c test/egcs-19990524/gcc/dwarfout.c
--- egcs-19990524/gcc/dwarfout.c	Sun Apr 18 09:09:27 1999
+++ test/egcs-19990524/gcc/dwarfout.c	Wed May 26 12:14:55 1999
@@ -50,8 +50,6 @@ extern time_t time PROTO ((time_t *)); /
 # define assert(e) do { if (! (e)) abort (); } while (0)
 #endif
 
-extern char *getpwd PROTO((void));
-
 /* IMPORTANT NOTE: Please see the file README.DWARF for important details
    regarding the GNU implementation of Dwarf.  */
 
diff -rup egcs-19990524/gcc/final.c test/egcs-19990524/gcc/final.c
--- egcs-19990524/gcc/final.c	Tue Apr 27 08:23:16 1999
+++ test/egcs-19990524/gcc/final.c	Wed May 26 12:15:11 1999
@@ -306,8 +306,6 @@ static void leaf_renumber_regs	PROTO((rt
 #ifdef HAVE_cc0
 static int alter_cond		PROTO((rtx));
 #endif
-
-extern char *getpwd ();
 
 /* Initialize data in final at the beginning of a compilation.  */
 
diff -rup egcs-19990524/gcc/protoize.c test/egcs-19990524/gcc/protoize.c
--- egcs-19990524/gcc/protoize.c	Fri Apr 16 15:52:36 1999
+++ test/egcs-19990524/gcc/protoize.c	Wed May 26 12:15:22 1999
@@ -109,8 +109,6 @@ extern char *version_string;
 #define my_open(file, mode, flag)	open((char *)file, mode, flag)
 #define my_chmod(file, mode)	chmod((char *)file, mode)
 
-extern char *getpwd ();
-
 static void usage PROTO ((void)) ATTRIBUTE_NORETURN;
 static void aux_info_corrupted PROTO ((void)) ATTRIBUTE_NORETURN;
 static void declare_source_confusing PROTO ((const char *)) ATTRIBUTE_NORETURN;


1999-05-27  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* repo.c (getpwd): Don't prototype.
	* xref.c (getpwd): Likewise

diff -rup egcs-19990524/gcc/cp/repo.c test/egcs-19990524/gcc/cp/repo.c
--- egcs-19990524/gcc/cp/repo.c	Fri Mar 26 02:44:49 1999
+++ test/egcs-19990524/gcc/cp/repo.c	Wed May 26 12:15:32 1999
@@ -33,8 +33,6 @@ Boston, MA 02111-1307, USA.  */
 #include "obstack.h"
 #include "toplev.h"
 
-extern char *getpwd PROTO((void));
-
 static tree repo_get_id PROTO((tree));
 static char *extract_string PROTO((char **));
 static char *get_base_filename PROTO((const char *));
diff -rup egcs-19990524/gcc/cp/xref.c test/egcs-19990524/gcc/cp/xref.c
--- egcs-19990524/gcc/cp/xref.c	Fri Mar 26 02:45:00 1999
+++ test/egcs-19990524/gcc/cp/xref.c	Wed May 26 12:15:39 1999
@@ -27,8 +27,6 @@ Boston, MA 02111-1307, USA.  */
 #include "input.h"
 #include "toplev.h"
 
-extern char *getpwd PROTO((void));
-
 /* The character(s) used to join a directory specification (obtained with
    getwd or equivalent) with a non-absolute file name.  */
 


1999-05-27  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* libiberty.h (getpwd): Prototype.

diff -rup egcs-19990524/include/libiberty.h test/egcs-19990524/include/libiberty.h
--- egcs-19990524/include/libiberty.h	Wed Apr  7 00:24:19 1999
+++ test/egcs-19990524/include/libiberty.h	Wed May 26 12:11:19 1999
@@ -51,6 +51,10 @@ extern char *concat PARAMS ((const char 
 
 extern int fdmatch PARAMS ((int fd1, int fd2));
 
+/* Get the working directory.  */
+
+extern char * getpwd PARAMS ((void));
+
 /* Get the amount of time the process has run, in microseconds.  */
 
 extern long get_run_time PARAMS ((void));


1999-05-27  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.

diff -rup egcs-19990524/libiberty/Makefile.in test/egcs-19990524/libiberty/Makefile.in
--- egcs-19990524/libiberty/Makefile.in	Mon Apr  5 10:28:56 1999
+++ test/egcs-19990524/libiberty/Makefile.in	Wed May 26 12:09:30 1999
@@ -116,8 +116,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 random.c rename.c rindex.c sigsetmask.c spaces.c \
@@ -128,7 +128,7 @@ CFILES = asprintf.c alloca.c argv.c atex
 
 # 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
@@ -241,6 +241,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
diff -rup egcs-19990524/libiberty/configure.in test/egcs-19990524/libiberty/configure.in
--- egcs-19990524/libiberty/configure.in	Thu May  6 16:57:00 1999
+++ test/egcs-19990524/libiberty/configure.in	Wed May 26 12:43:28 1999
@@ -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
diff -rup egcs-19990524/libiberty/getpwd.c test/egcs-19990524/libiberty/getpwd.c
--- egcs-19990524/libiberty/getpwd.c	Wed May 26 12:48:21 1999
+++ test/egcs-19990524/libiberty/getpwd.c	Wed May 26 12:42:42 1999
@@ -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 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__ */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]