-# 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
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) $<
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)
$(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
#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
#ifdef NDIR
#include <ndir.h>
#endif /* NDIR */
-#endif /* DIRENT or _POSIX_VERSION */
+#endif /* DIRENT */
#ifdef VOID_CLOSEDIR
/* Fake a return value. */
#include <sys/types.h>
#include "fsusage.h"
+#include "safe-stat.h"
int statfs ();
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;
#include <sys/types.h>
#include <sys/stat.h>
+#include "safe-stat.h"
+
#ifdef STAT_MACROS_BROKEN
#ifdef S_ISDIR
#undef S_ISDIR
{
struct stat stats;
- return stat (path, &stats) == 0 && S_ISDIR (stats.st_mode);
+ return SAFE_STAT (path, &stats) == 0 && S_ISDIR (stats.st_mode);
}
typedef int gid_t;
#endif
+#include "safe-stat.h"
void error ();
/* Ensure that the directory ARGPATH exists.
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. */
while ((slash = index (slash, '/')))
{
*slash = '\0';
- if (stat (dirpath, &stats))
+ if (SAFE_STAT (dirpath, &stats))
{
if (mkdir (dirpath, tmp_mode))
{
/* 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);
#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. */
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;
#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
#ifdef NDIR
#include <ndir.h>
#endif /* NDIR */
-#endif /* DIRENT or _POSIX_VERSION */
+#endif /* DIRENT */
#ifdef VOID_CLOSEDIR
/* Fake a return value. */