GNU file utilities FILEUTILS-3_9e
authorJim Meyering <jim@meyering.net>
Sat, 30 Jul 1994 18:12:17 +0000 (18:12 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 30 Jul 1994 18:12:17 +0000 (18:12 +0000)
lib/Makefile.in
lib/backupfile.c
lib/fsusage.c
lib/isdir.c
lib/makepath.c
lib/rename.c
lib/savedir.c

index fc6f35d..235a9ca 100644 (file)
@@ -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 @@ OBJECTS = getdate.o posixtm.o \
 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 @@ distclean: clean
        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 @@ libfu.a: $(OBJECTS)
        $(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
index e6956ee..2ef0f0b 100644 (file)
 #include <strings.h>
 #endif
 
-#if defined(DIRENT) || defined(_POSIX_VERSION)
+#ifdef DIRENT
 #include <dirent.h>
 #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 <ndir.h>
 #endif /* NDIR */
-#endif /* DIRENT or _POSIX_VERSION */
+#endif /* DIRENT */
 
 #ifdef VOID_CLOSEDIR
 /* Fake a return value. */
index d0d7465..d60a4c6 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <sys/types.h>
 #include "fsusage.h"
+#include "safe-stat.h"
 
 int statfs ();
 
@@ -211,7 +212,7 @@ statfs (path, fsb)
   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;
index 2c75bec..b1dbc2d 100644 (file)
@@ -29,6 +29,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include "safe-stat.h"
+
 #ifdef STAT_MACROS_BROKEN
 #ifdef S_ISDIR
 #undef S_ISDIR
@@ -48,5 +50,5 @@ isdir (path)
 {
   struct stat stats;
 
-  return stat (path, &stats) == 0 && S_ISDIR (stats.st_mode);
+  return SAFE_STAT (path, &stats) == 0 && S_ISDIR (stats.st_mode);
 }
index bb6a09c..e109865 100644 (file)
@@ -86,6 +86,7 @@ typedef int uid_t;
 typedef int gid_t;
 #endif
 
+#include "safe-stat.h"
 void error ();
 
 /* Ensure that the directory ARGPATH exists.
@@ -121,7 +122,7 @@ make_path (argpath, mode, parent_mode, owner, group, verbose_fmt_string)
   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 @@ make_path (argpath, mode, parent_mode, owner, group, verbose_fmt_string)
       while ((slash = index (slash, '/')))
        {
          *slash = '\0';
-         if (stat (dirpath, &stats))
+         if (SAFE_STAT (dirpath, &stats))
            {
              if (mkdir (dirpath, tmp_mode))
                {
@@ -206,7 +207,10 @@ make_path (argpath, mode, parent_mode, owner, group, verbose_fmt_string)
       /* 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);
index 1502436..cd291b4 100644 (file)
@@ -43,6 +43,8 @@ extern int errno;
 #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 @@ rename (from, to)
   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;
index 7080c8e..b831c1f 100644 (file)
 #include <unistd.h>
 #endif
 
-#if defined(DIRENT) || defined(_POSIX_VERSION)
+#ifdef DIRENT
 #include <dirent.h>
 #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 <ndir.h>
 #endif /* NDIR */
-#endif /* DIRENT or _POSIX_VERSION */
+#endif /* DIRENT */
 
 #ifdef VOID_CLOSEDIR
 /* Fake a return value. */