summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1994-07-30 18:12:17 +0000
committerJim Meyering <jim@meyering.net>1994-07-30 18:12:17 +0000
commitd29b6e1377db5088eacebe30f03243d785752e1a (patch)
treea90de2653a3e9821d2958bc7813048f11498baa9
parentaee34fb09c156cd049ff12c5bb4a89167a82ee5e (diff)
downloadgnulib-d29b6e1377db5088eacebe30f03243d785752e1a.tar.gz
GNU file utilitiesFILEUTILS-3_9e
-rw-r--r--lib/Makefile.in41
-rw-r--r--lib/backupfile.c6
-rw-r--r--lib/fsusage.c3
-rw-r--r--lib/isdir.c4
-rw-r--r--lib/makepath.c10
-rw-r--r--lib/rename.c6
-rw-r--r--lib/savedir.c6
7 files changed, 56 insertions, 20 deletions
diff --git a/lib/Makefile.in b/lib/Makefile.in
index fc6f35d95d..235a9ca960 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -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
diff --git a/lib/backupfile.c b/lib/backupfile.c
index e6956ee2ae..2ef0f0b48d 100644
--- a/lib/backupfile.c
+++ b/lib/backupfile.c
@@ -45,10 +45,10 @@
#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. */
diff --git a/lib/fsusage.c b/lib/fsusage.c
index d0d746556e..d60a4c6a73 100644
--- a/lib/fsusage.c
+++ b/lib/fsusage.c
@@ -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;
diff --git a/lib/isdir.c b/lib/isdir.c
index 2c75bec9bd..b1dbc2d70a 100644
--- a/lib/isdir.c
+++ b/lib/isdir.c
@@ -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);
}
diff --git a/lib/makepath.c b/lib/makepath.c
index bb6a09c12c..e109865c55 100644
--- a/lib/makepath.c
+++ b/lib/makepath.c
@@ -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);
diff --git a/lib/rename.c b/lib/rename.c
index 1502436f05..cd291b4905 100644
--- a/lib/rename.c
+++ b/lib/rename.c
@@ -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;
diff --git a/lib/savedir.c b/lib/savedir.c
index 7080c8ecc1..b831c1fe92 100644
--- a/lib/savedir.c
+++ b/lib/savedir.c
@@ -34,10 +34,10 @@
#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. */