# HG changeset patch # User Jim Meyering # Date 775591937 0 # Node ID 555e15f4598a72d11bdd5f2486e6f385910b73e8 # Parent b701d2d6b4043753024f741a5b03b9c33e53b095 GNU file utilities diff -r b701d2d6b404 -r 555e15f4598a lib/Makefile.in --- a/lib/Makefile.in Fri Jul 01 19:45:39 1994 +0000 +++ b/lib/Makefile.in Sat Jul 30 18:12:17 1994 +0000 @@ -1,5 +1,5 @@ -# Makefile for library files used by GNU fileutils. -# Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc. +# Makefile for library files used by GNU file utilities. +# Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,15 +44,19 @@ argmatch.o backupfile.o basename.o dirname.o eaccess.o \ error.o filemode.o full-write.o getopt.o getopt1.o \ getversion.o group-member.o idcache.o isdir.o long-options.o makepath.o \ -modechange.o safe-read.o savedir.o \ +modechange.o safe-read.o safe-stat.o safe-lstat.o savedir.o \ stripslash.o xgetcwd.o xmalloc.o xstrdup.o userspec.o yesno.o \ @LIBOBJS@ @ALLOCA@ DISTFILES = Makefile.in backupfile.h getopt.h modechange.h \ -fnmatch.h fsusage.h mountlist.h pathmax.h $(SOURCES) +fnmatch.h fsusage.h mountlist.h pathmax.h safe-xstat.c.in safe-xstat.h.in \ +$(SOURCES) all: libfu.a +.SUFFIXES = +.SUFFIXES = .c .o + .c.o: $(CC) -c $(CPPFLAGS) $(DEFS) -I.. -I$(srcdir) $(CFLAGS) $< @@ -77,12 +81,13 @@ rm -f Makefile *.tab.c getdate.c *posixtm.c realclean: distclean - rm -f TAGS + rm -f TAGS safe-stat.c safe-stat.h safe-lstat.c safe-lstat.h +distdir = ../`cat ../.fname`/lib dist: $(DISTFILES) for file in $(DISTFILES); do \ - ln $$file ../`cat ../.fname`/lib \ - || cp -p $$file ../`cat ../.fname`/lib; \ + ln $$file $(distdir) \ + || { echo copying $$file instead; cp -p $$file $(distdir);}; \ done libfu.a: $(OBJECTS) @@ -90,6 +95,28 @@ $(AR) cr $@ $(OBJECTS) -$(RANLIB) $@ +extract_stat = sed -e 's/@l@//g' -e 's/@L@//g' +extract_lstat = sed -e 's/@l@/l/g' -e 's/@L@/L/g' + +safe-lstat.c: safe-xstat.c.in + $(extract_lstat) safe-xstat.c.in > $@-tmp + mv $@-tmp $@ + +safe-lstat.h: safe-xstat.h.in + $(extract_lstat) safe-xstat.h.in > $@-tmp + mv $@-tmp $@ + +safe-stat.c: safe-xstat.c.in + $(extract_stat) safe-xstat.c.in > $@-tmp + mv $@-tmp $@ + +safe-stat.h: safe-xstat.h.in + $(extract_stat) safe-xstat.h.in > $@-tmp + mv $@-tmp $@ + +safe-stat.o: safe-stat.h +safe-lstat.o: safe-lstat.h + # Since this directory contains two parsers, we have to be careful to avoid # running two $(YACC)s during parallel makes. See below. getdate.c: getdate.y diff -r b701d2d6b404 -r 555e15f4598a lib/backupfile.c --- a/lib/backupfile.c Fri Jul 01 19:45:39 1994 +0000 +++ b/lib/backupfile.c Sat Jul 30 18:12:17 1994 +0000 @@ -45,10 +45,10 @@ #include #endif -#if defined(DIRENT) || defined(_POSIX_VERSION) +#ifdef DIRENT #include #define NLENGTH(direct) (strlen((direct)->d_name)) -#else /* not (DIRENT or _POSIX_VERSION) */ +#else /* not DIRENT */ #define dirent direct #define NLENGTH(direct) ((direct)->d_namlen) #ifdef SYSNDIR @@ -60,7 +60,7 @@ #ifdef NDIR #include #endif /* NDIR */ -#endif /* DIRENT or _POSIX_VERSION */ +#endif /* DIRENT */ #ifdef VOID_CLOSEDIR /* Fake a return value. */ diff -r b701d2d6b404 -r 555e15f4598a lib/fsusage.c --- a/lib/fsusage.c Fri Jul 01 19:45:39 1994 +0000 +++ b/lib/fsusage.c Sat Jul 30 18:12:17 1994 +0000 @@ -28,6 +28,7 @@ #include #include "fsusage.h" +#include "safe-stat.h" int statfs (); @@ -211,7 +212,7 @@ struct stat stats; struct dustat fsd; - if (stat (path, &stats)) + if (SAFE_STAT (path, &stats)) return -1; if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd))) return -1; diff -r b701d2d6b404 -r 555e15f4598a lib/isdir.c --- a/lib/isdir.c Fri Jul 01 19:45:39 1994 +0000 +++ b/lib/isdir.c Sat Jul 30 18:12:17 1994 +0000 @@ -29,6 +29,8 @@ #include #include +#include "safe-stat.h" + #ifdef STAT_MACROS_BROKEN #ifdef S_ISDIR #undef S_ISDIR @@ -48,5 +50,5 @@ { struct stat stats; - return stat (path, &stats) == 0 && S_ISDIR (stats.st_mode); + return SAFE_STAT (path, &stats) == 0 && S_ISDIR (stats.st_mode); } diff -r b701d2d6b404 -r 555e15f4598a lib/makepath.c --- a/lib/makepath.c Fri Jul 01 19:45:39 1994 +0000 +++ b/lib/makepath.c Sat Jul 30 18:12:17 1994 +0000 @@ -86,6 +86,7 @@ typedef int gid_t; #endif +#include "safe-stat.h" void error (); /* Ensure that the directory ARGPATH exists. @@ -121,7 +122,7 @@ dirpath = (char *) alloca (strlen (argpath) + 1); strcpy (dirpath, argpath); - if (stat (dirpath, &stats)) + if (SAFE_STAT (dirpath, &stats)) { char *slash; int tmp_mode; /* Initial perms for leading dirs. */ @@ -155,7 +156,7 @@ while ((slash = index (slash, '/'))) { *slash = '\0'; - if (stat (dirpath, &stats)) + if (SAFE_STAT (dirpath, &stats)) { if (mkdir (dirpath, tmp_mode)) { @@ -206,7 +207,10 @@ /* We're done making leading directories. Make the final component of the path. */ - if (mkdir (dirpath, mode)) + /* The path could end in "/." or contain "/..", so test + if we really have to create the directory. */ + + if (SAFE_STAT (dirpath, &stats) && mkdir (dirpath, mode)) { error (0, errno, "cannot make directory `%s'", dirpath); umask (oldmask); diff -r b701d2d6b404 -r 555e15f4598a lib/rename.c --- a/lib/rename.c Fri Jul 01 19:45:39 1994 +0000 +++ b/lib/rename.c Sat Jul 30 18:12:17 1994 +0000 @@ -43,6 +43,8 @@ #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif +#include "safe-stat.h" + /* Rename file FROM to file TO. Return 0 if successful, -1 if not. */ @@ -54,13 +56,13 @@ struct stat from_stats, to_stats; int pid, status; - if (stat (from, &from_stats)) + if (SAFE_STAT (from, &from_stats)) return -1; /* Be careful not to unlink `from' if it happens to be equal to `to' or (on filesystems that silently truncate filenames after 14 characters) if `from' and `to' share the significant characters. */ - if (stat (to, &to_stats)) + if (SAFE_STAT (to, &to_stats)) { if (errno != ENOENT) return -1; diff -r b701d2d6b404 -r 555e15f4598a lib/savedir.c --- a/lib/savedir.c Fri Jul 01 19:45:39 1994 +0000 +++ b/lib/savedir.c Sat Jul 30 18:12:17 1994 +0000 @@ -34,10 +34,10 @@ #include #endif -#if defined(DIRENT) || defined(_POSIX_VERSION) +#ifdef DIRENT #include #define NLENGTH(direct) (strlen((direct)->d_name)) -#else /* not (DIRENT or _POSIX_VERSION) */ +#else /* not DIRENT */ #define dirent direct #define NLENGTH(direct) ((direct)->d_namlen) #ifdef SYSNDIR @@ -49,7 +49,7 @@ #ifdef NDIR #include #endif /* NDIR */ -#endif /* DIRENT or _POSIX_VERSION */ +#endif /* DIRENT */ #ifdef VOID_CLOSEDIR /* Fake a return value. */