GNU file utilities FILEUTILS-3_9h
authorJim Meyering <jim@meyering.net>
Sun, 2 Oct 1994 05:35:03 +0000 (05:35 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 2 Oct 1994 05:35:03 +0000 (05:35 +0000)
25 files changed:
lib/Makefile.in
lib/argmatch.c
lib/backupfile.c
lib/dirname.c
lib/fileblocks.c
lib/filemode.c
lib/fsusage.c
lib/ftruncate.c
lib/full-write.c
lib/getversion.c
lib/idcache.c
lib/isdir.c
lib/makepath.c
lib/mkdir.c
lib/modechange.c
lib/mountlist.c
lib/rename.c
lib/rmdir.c [new file with mode: 0644]
lib/safe-read.c
lib/savedir.c
lib/strdup.c
lib/stripslash.c
lib/userspec.c
lib/xstrdup.c
lib/yesno.c

index 45780d8..b84df8b 100644 (file)
@@ -23,21 +23,19 @@ VPATH = @srcdir@
 CC = @CC@
 AR = ar
 RANLIB = @RANLIB@
-DEFS = -DCONFIG_BROKETS @DEFS@
+DEFS = -Dlint @DEFS@
 CFLAGS = @CFLAGS@
 YACC = @YACC@
 
-prefix = @prefix@
-exec_prefix = $(prefix)
+exec_prefix = @exec_prefix@
 libdir = $(exec_prefix)/lib
-
 SOURCES = getdate.y posixtm.y \
 argmatch.c backupfile.c basename.c dirname.c eaccess.c \
 error.c filemode.c fsusage.c full-write.c getopt.c getopt1.c \
 getversion.c group-member.c idcache.c isdir.c makepath.c \
 modechange.c mountlist.c safe-read.c savedir.c \
 stripslash.c xgetcwd.c xmalloc.c xstrdup.c userspec.c yesno.c \
-fileblocks.c fnmatch.c ftruncate.c mkdir.c mktime.c rename.c stpcpy.c \
+fileblocks.c fnmatch.c ftruncate.c mkdir.c mktime.c rename.c rmdir.c stpcpy.c \
 strdup.c strstr.c alloca.c long-options.c
 
 OBJECTS = getdate.o posixtm.o \
@@ -49,19 +47,21 @@ 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 safe-xstat.c.in safe-xstat.h.in \
+fnmatch.h fsusage.h mountlist.h pathmax.h safe-xstat.cin safe-xstat.hin \
 getdate.c posixtm.c $(SOURCES)
 
 all: libfu.a
 
-.SUFFIXES =
-.SUFFIXES = .c .o
+.SUFFIXES:
+.SUFFIXES: .c .o
 
 .c.o:
-       $(CC) -c $(CPPFLAGS) $(DEFS) -I.. -I$(srcdir) $(CFLAGS) $<
+       $(CC) -c $(CPPFLAGS) $(DEFS) -I. -I.. -I$(srcdir) $(CFLAGS) $<
 
 Makefile: ../config.status Makefile.in
-       CONFIG_FILES=$@ CONFIG_HEADERS= ../config.status
+       cd ..; CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status
+
+installdirs:
 
 install: all
 
@@ -78,12 +78,13 @@ clean:
 mostlyclean: clean
 
 distclean: clean
-       rm -f Makefile *.tab.c getdate.c *posixtm.c
+       rm -f Makefile *.tab.c getdate.c *posixtm.c \
+         safe-stat.c safe-stat.h safe-lstat.c safe-lstat.h
 
 realclean: distclean
-       rm -f TAGS safe-stat.c safe-stat.h safe-lstat.c safe-lstat.h 
+       rm -f TAGS
 
-distdir = ../`cat ../.fname`/lib 
+distdir = ../`cat ../distname`/$(subdir)
 dist: $(DISTFILES)
        for file in $(DISTFILES); do \
          ln $$file $(distdir) \
@@ -98,21 +99,21 @@ libfu.a: $(OBJECTS)
 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.c: safe-xstat.cin
+       $(extract_lstat) $(srcdir)/safe-xstat.cin > $@-t
+       mv $@-t $@
 
-safe-lstat.h: safe-xstat.h.in
-       $(extract_lstat) safe-xstat.h.in > $@-tmp
-       mv $@-tmp $@
+safe-lstat.h: safe-xstat.hin
+       $(extract_lstat) $(srcdir)/safe-xstat.hin > $@-t
+       mv $@-t $@
 
-safe-stat.c: safe-xstat.c.in
-       $(extract_stat) safe-xstat.c.in > $@-tmp
-       mv $@-tmp $@
+safe-stat.c: safe-xstat.cin
+       $(extract_stat) $(srcdir)/safe-xstat.cin > $@-t
+       mv $@-t $@
 
-safe-stat.h: safe-xstat.h.in
-       $(extract_stat) safe-xstat.h.in > $@-tmp
-       mv $@-tmp $@
+safe-stat.h: safe-xstat.hin
+       $(extract_stat) $(srcdir)/safe-xstat.hin > $@-t
+       mv $@-t $@
 
 safe-stat.o: safe-stat.h
 safe-lstat.o: safe-lstat.h
index 17e088b..154736f 100644 (file)
 /* Written by David MacKenzie <djm@ai.mit.edu> */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <stdio.h>
index 2ef0f0b..2888034 100644 (file)
    Some algorithms adapted from GNU Emacs. */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <stdio.h>
 #include <strings.h>
 #endif
 
-#ifdef DIRENT
+#ifdef HAVE_DIRENT_H
 #include <dirent.h>
 #define NLENGTH(direct) (strlen((direct)->d_name))
-#else /* not DIRENT */
+#else /* not HAVE_DIRENT_H */
 #define dirent direct
 #define NLENGTH(direct) ((direct)->d_namlen)
-#ifdef SYSNDIR
+#ifdef HAVE_SYS_NDIR_H
 #include <sys/ndir.h>
-#endif /* SYSNDIR */
-#ifdef SYSDIR
+#endif /* HAVE_SYS_NDIR_H */
+#ifdef HAVE_SYS_DIR_H
 #include <sys/dir.h>
-#endif /* SYSDIR */
-#ifdef NDIR
+#endif /* HAVE_SYS_DIR_H */
+#ifdef HAVE_NDIR_H
 #include <ndir.h>
-#endif /* NDIR */
-#endif /* DIRENT */
+#endif /* HAVE_NDIR_H */
+#endif /* HAVE_DIRENT_H */
 
-#ifdef VOID_CLOSEDIR
+#ifdef CLOSEDIR_VOID
 /* Fake a return value. */
 #define CLOSEDIR(d) (closedir (d), 0)
 #else
index cb53eb4..9290614 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #ifdef STDC_HEADERS
index ee82f75..83ac04f 100644 (file)
 /* Written by Brian L. Matthews, blm@6sceng.UUCP. */
 \f
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #if !defined (HAVE_ST_BLOCKS) && !defined(_POSIX_SOURCE)
index 8b99228..e88fc12 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 \f
 #ifdef HAVE_CONFIG_H
-#if defined (emacs) || defined (CONFIG_BROKETS)
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <sys/types.h>
 #endif
 #endif
 
-#ifdef STAT_MACROS_BROKEN
-#ifdef S_ISBLK
+#ifdef STAT_MACROS_BROKEN
 #undef S_ISBLK
-#endif
-#ifdef S_ISCHR
 #undef S_ISCHR
-#endif
-#ifdef S_ISDIR
 #undef S_ISDIR
-#endif
-#ifdef S_ISFIFO
 #undef S_ISFIFO
-#endif
-#ifdef S_ISLNK
 #undef S_ISLNK
-#endif
-#ifdef S_ISMPB
 #undef S_ISMPB
-#endif
-#ifdef S_ISMPC
 #undef S_ISMPC
-#endif
-#ifdef S_ISNWK
 #undef S_ISNWK
-#endif
-#ifdef S_ISREG
 #undef S_ISREG
-#endif
-#ifdef S_ISSOCK
 #undef S_ISSOCK
-#endif
-#endif /* STAT_MACROS_BROKEN.  */
+#endif /* STAT_MACROS_BROKEN.  */
 
 #if !defined(S_ISBLK) && defined(S_IFBLK)
 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
index d60a4c6..9bef62a 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <sys/types.h>
index 04156b7..1272ee7 100644 (file)
@@ -2,24 +2,12 @@
    This file is in the public domain.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <sys/types.h>
 #include <fcntl.h>
 
-#include <errno.h>
-#ifndef STDC_HEADERS
-extern int errno;
-#endif
-
 #ifdef F_CHSIZE
 
 int
@@ -36,7 +24,7 @@ ftruncate (fd, length)
 /* By William Kucharski <kucharsk@netcom.com>.  */
 
 #include <sys/stat.h>
-
+#include <errno.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -96,6 +84,11 @@ ftruncate (fd, length)
 
 #else /* not F_CHSIZE nor F_FREESP nor HAVE_CHSIZE */
 
+#include <errno.h>
+#ifndef errno
+extern int errno;
+#endif
+
 int
 ftruncate (fd, length)
      int fd;
index 6e2e446..339fb1a 100644 (file)
    */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <sys/types.h>
@@ -47,7 +40,7 @@ int
 full_write (desc, ptr, len)
      int desc;
      char *ptr;
-     int len;
+     size_t len;
 {
   int total_written;
 
index 78fda75..10b60aa 100644 (file)
 /* Written by David MacKenzie <djm@gnu.ai.mit.edu> */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include "backupfile.h"
index bafae74..34dcc07 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <stdio.h>
index b1dbc2d..dbc9bd0 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <sys/types.h>
 
 #include "safe-stat.h"
 
-#ifdef STAT_MACROS_BROKEN
-#ifdef S_ISDIR
+#ifdef STAT_MACROS_BROKEN
 #undef S_ISDIR
-#endif
-#endif /* STAT_MACROS_BROKEN.  */
+#endif /* STAT_MACROS_BROKEN.  */
 
 #if !defined(S_ISDIR) && defined(S_IFDIR)
 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
index e109865..f0303fa 100644 (file)
    Jim Meyering <meyering@cs.utexas.edu>.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #ifdef __GNUC__
@@ -50,11 +43,9 @@ char *alloca ();
 #include <unistd.h>
 #endif
 
-#ifdef STAT_MACROS_BROKEN
-#ifdef S_ISDIR
+#ifdef STAT_MACROS_BROKEN
 #undef S_ISDIR
-#endif
-#endif /* STAT_MACROS_BROKEN.  */
+#endif /* STAT_MACROS_BROKEN.  */
 
 #if !defined(S_ISDIR) && defined(S_IFDIR)
 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
index 28c8932..3726cbb 100644 (file)
@@ -1,4 +1,4 @@
-/* mkrmdir.c -- BSD compatible directory functions for System V
+/* mkdir.c -- BSD compatible make directory function for System V
    Copyright (C) 1988, 1990 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
 
 #include <sys/types.h>
 #include <sys/stat.h>
+
 #include <errno.h>
-#ifndef STDC_HEADERS
+#ifndef errno
 extern int errno;
 #endif
 
-#ifdef STAT_MACROS_BROKEN
-#ifdef S_ISDIR
+#ifdef STAT_MACROS_BROKEN
 #undef S_ISDIR
 #endif
-#endif /* STAT_MACROS_BROKEN.  */
 
 #if !defined(S_ISDIR) && defined(S_IFDIR)
 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
 #endif
 
-/* mkdir and rmdir adapted from GNU tar.  */
+#include "safe-stat.h"
+
+/* mkdir adapted from GNU tar.  */
 
 /* Make directory DPATH, with permission mode DMODE.
 
@@ -64,9 +65,9 @@ mkdir (dpath, dmode)
   int cpid, status;
   struct stat statbuf;
 
-  if (stat (dpath, &statbuf) == 0)
+  if (SAFE_STAT (dpath, &statbuf) == 0)
     {
-      errno = EEXIST;          /* stat worked, so it already exists.  */
+      errno = EEXIST;          /* stat worked, it already exists */
       return -1;
     }
 
@@ -77,70 +78,36 @@ mkdir (dpath, dmode)
   cpid = fork ();
   switch (cpid)
     {
-    case -1:                   /* Cannot fork.  */
-      return -1;               /* errno is set already.  */
+    case -1:                   /* cannot fork */
+      return -1;               /* errno already set */
+
+    case 0:                    /* child process */
 
-    case 0:                    /* Child process.  */
       /* Cheap hack to set mode of new directory.  Since this child
-        process is going away anyway, we zap its umask.
-        This won't suffice to set SUID, SGID, etc. on this
-        directory, so the parent process calls chmod afterward.  */
-      status = umask (0);      /* Get current umask.  */
-      umask (status | (0777 & ~dmode));        /* Set for mkdir.  */
+        process is going away anyway, we zap its umask.  This won't
+        suffice to set SUID, SGID, etc. on this directory, so the parent
+        process calls chmod afterward.  */
+
+      status = umask (0);
+      umask (status | (0777 & ~dmode));
       execl ("/bin/mkdir", "mkdir", dpath, (char *) 0);
       _exit (1);
 
-    default:                   /* Parent process.  */
-      while (wait (&status) != cpid) /* Wait for kid to finish.  */
-       /* Do nothing.  */ ;
+    default:                   /* parent process */
 
-      if (status & 0xFFFF)
-       {
-         errno = EIO;          /* /bin/mkdir failed.  */
-         return -1;
-       }
-      return chmod (dpath, dmode);
-    }
-}
-
-/* Remove directory DPATH.
-   Return 0 if successful, -1 if not.  */
+      /* Wait for kid to finish.  */
 
-int
-rmdir (dpath)
-     char *dpath;
-{
-  int cpid, status;
-  struct stat statbuf;
-
-  if (stat (dpath, &statbuf) != 0)
-    return -1;                 /* stat set errno.  */
-
-  if (!S_ISDIR (statbuf.st_mode))
-    {
-      errno = ENOTDIR;
-      return -1;
-    }
-
-  cpid = fork ();
-  switch (cpid)
-    {
-    case -1:                   /* Cannot fork.  */
-      return -1;               /* errno is set already.  */
-
-    case 0:                    /* Child process.  */
-      execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
-      _exit (1);
-
-    default:                   /* Parent process.  */
-      while (wait (&status) != cpid) /* Wait for kid to finish.  */
+      while (wait (&status) != cpid)
        /* Do nothing.  */ ;
 
       if (status & 0xFFFF)
        {
-         errno = EIO;          /* /bin/rmdir failed.  */
+
+         /* /bin/mkdir failed.  */
+
+         errno = EIO;
          return -1;
        }
-      return 0;
+      return chmod (dpath, dmode);
     }
 }
index e1212e9..8eb8dc5 100644 (file)
    performance gain. */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <sys/types.h>
@@ -49,11 +42,9 @@ char *malloc ();
 #define NULL 0
 #endif
 
-#ifdef STAT_MACROS_BROKEN
-#ifdef S_ISDIR
+#ifdef STAT_MACROS_BROKEN
 #undef S_ISDIR
-#endif
-#endif /* STAT_MACROS_BROKEN.  */
+#endif /* STAT_MACROS_BROKEN.  */
 
 #if !defined(S_ISDIR) && defined(S_IFDIR)
 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
index aaf28ea..a39461d 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <stdio.h>
index cd291b4..6319397 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <sys/types.h>
 extern int errno;
 #endif
 
-#ifdef STAT_MACROS_BROKEN
-#ifdef S_ISDIR
+#ifdef STAT_MACROS_BROKEN
 #undef S_ISDIR
-#endif
-#endif /* STAT_MACROS_BROKEN.  */
+#endif /* STAT_MACROS_BROKEN.  */
 
 #if !defined(S_ISDIR) && defined(S_IFDIR)
 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
diff --git a/lib/rmdir.c b/lib/rmdir.c
new file mode 100644 (file)
index 0000000..f10b396
--- /dev/null
@@ -0,0 +1,95 @@
+/* rmdir.c -- BSD compatible remove directory function for System V
+   Copyright (C) 1988, 1990 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+#ifdef HAVE_CONFIG_H
+#if defined (CONFIG_BROKETS)
+/* We use <config.h> instead of "config.h" so that a compilation
+   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
+   (which it would do because it found this file in $srcdir).  */
+#include <config.h>
+#else
+#include "config.h"
+#endif
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#ifndef errno
+extern int errno;
+#endif
+
+#ifdef STAT_MACROS_BROKEN
+#undef S_ISDIR
+#endif
+
+#if !defined(S_ISDIR) && defined(S_IFDIR)
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#endif
+
+#include "safe-stat.h"
+
+/* rmdir adapted from GNU tar.  */
+
+/* Remove directory DPATH.
+   Return 0 if successful, -1 if not.  */
+
+int
+rmdir (dpath)
+     char *dpath;
+{
+  int cpid, status;
+  struct stat statbuf;
+
+  if (SAFE_STAT (dpath, &statbuf) != 0)
+    return -1;                 /* errno already set */
+
+  if (!S_ISDIR (statbuf.st_mode))
+    {
+      errno = ENOTDIR;
+      return -1;
+    }
+
+  cpid = fork ();
+  switch (cpid)
+    {
+    case -1:                   /* cannot fork */
+      return -1;               /* errno already set */
+
+    case 0:                    /* child process */
+      execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
+      _exit (1);
+
+    default:                   /* parent process */
+
+      /* Wait for kid to finish.  */
+
+      while (wait (&status) != cpid)
+       /* Do nothing.  */ ;
+
+      if (status & 0xFFFF)
+       {
+
+         /* /bin/rmdir failed.  */
+
+         errno = EIO;
+         return -1;
+       }
+      return 0;
+    }
+}
index 2e131e1..22e705a 100644 (file)
    */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <sys/types.h>
index b831c1f..32c793b 100644 (file)
 /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <sys/types.h>
 #include <unistd.h>
 #endif
 
-#ifdef DIRENT
+#ifdef HAVE_DIRENT_H
 #include <dirent.h>
 #define NLENGTH(direct) (strlen((direct)->d_name))
-#else /* not DIRENT */
+#else /* not HAVE_DIRENT_H */
 #define dirent direct
 #define NLENGTH(direct) ((direct)->d_namlen)
-#ifdef SYSNDIR
+#ifdef HAVE_SYS_NDIR_H
 #include <sys/ndir.h>
-#endif /* SYSNDIR */
-#ifdef SYSDIR
+#endif /* HAVE_SYS_NDIR_H */
+#ifdef HAVE_SYS_DIR_H
 #include <sys/dir.h>
-#endif /* SYSDIR */
-#ifdef NDIR
+#endif /* HAVE_SYS_DIR_H */
+#ifdef HAVE_NDIR_H
 #include <ndir.h>
-#endif /* NDIR */
-#endif /* DIRENT */
+#endif /* HAVE_NDIR_H */
+#endif /* HAVE_DIRENT_H */
 
-#ifdef VOID_CLOSEDIR
+#ifdef CLOSEDIR_VOID
 /* Fake a return value. */
 #define CLOSEDIR(d) (closedir (d), 0)
 #else
index cc0db6f..1d60f13 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #ifdef STDC_HEADERS
index 5f40364..67330e5 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
index 75000e8..67f1583 100644 (file)
 /* Written by David MacKenzie <djm@gnu.ai.mit.edu>.  */
 \f
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #ifdef __GNUC__
index 4c5749e..27cd0c6 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
index 5e413ec..c689777 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
-#if defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
-   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
-   (which it would do because it found this file in $srcdir).  */
 #include <config.h>
-#else
-#include "config.h"
-#endif
 #endif
 
 #include <stdio.h>