summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1994-07-30 16:34:17 +0000
committerJim Meyering <jim@meyering.net>1994-07-30 16:34:17 +0000
commit32bd426778e4d37e233fe06ce66eb72b4a84c883 (patch)
tree81eae5822f0dba853b9116c074fb3a2a55ba8faa
parenta272d8b0c6e62937ef7b69e3ca750e34fd3e3152 (diff)
downloadcoreutils-32bd426778e4d37e233fe06ce66eb72b4a84c883.tar.xz
.
-rw-r--r--src/df.c14
-rw-r--r--src/du.c15
-rw-r--r--src/install.c5
-rw-r--r--src/ln.c5
-rw-r--r--src/ls.c10
-rw-r--r--src/mv.c7
-rw-r--r--src/rm.c3
-rw-r--r--src/touch.c5
8 files changed, 39 insertions, 25 deletions
diff --git a/src/df.c b/src/df.c
index 956c9d675..c1457bc35 100644
--- a/src/df.c
+++ b/src/df.c
@@ -51,6 +51,7 @@
#include "fsusage.h"
#include "system.h"
#include "version.h"
+#include "safe-stat.h"
char *xmalloc ();
char *xstrdup ();
@@ -206,14 +207,21 @@ main (argc, argv)
if (show_help)
usage (0);
- if (optind != argc)
+ if (optind == argc)
+ {
+#ifdef lint
+ /* Suppress `used before initialized' warning. */
+ stats = NULL;
+#endif
+ }
+ else
{
/* stat all the given entries to make sure they get automounted,
if necessary, before reading the filesystem table. */
stats = (struct stat *)
xmalloc ((argc - optind) * sizeof (struct stat));
for (i = optind; i < argc; ++i)
- if (stat (argv[i], &stats[i - optind]))
+ if (SAFE_STAT (argv[i], &stats[i - optind]))
{
error (0, errno, "%s", argv[i]);
exit_status = 1;
@@ -325,7 +333,7 @@ show_point (point, statp)
{
if (me->me_dev == (dev_t) -1)
{
- if (stat (me->me_mountdir, &disk_stats) == 0)
+ if (SAFE_STAT (me->me_mountdir, &disk_stats) == 0)
me->me_dev = disk_stats.st_dev;
else
{
diff --git a/src/du.c b/src/du.c
index b3a9a83ef..b53775a81 100644
--- a/src/du.c
+++ b/src/du.c
@@ -56,9 +56,8 @@
#include <sys/types.h>
#include "system.h"
#include "version.h"
-
-int lstat ();
-int stat ();
+#include "safe-stat.h"
+#include "safe-lstat.h"
/* Initial number of entries in each hash table entry's table of inodes. */
#define INITIAL_HASH_MODULE 100
@@ -238,7 +237,7 @@ main (argc, argv)
cwd_only[1] = "NULL";
program_name = argv[0];
- xstat = lstat;
+ xstat = safe_lstat;
output_size = getenv ("POSIXLY_CORRECT") ? size_blocks : size_kilobytes;
while ((c = getopt_long (argc, argv, "abcklsxDLS", long_options, (int *) 0))
@@ -282,7 +281,7 @@ main (argc, argv)
break;
case 'L':
- xstat = stat;
+ xstat = safe_stat;
break;
case 'S':
@@ -333,7 +332,7 @@ du_files (files)
error (1, errno, "cannot get current directory");
/* Remember the inode and device number of the current directory. */
- if (stat (".", &stat_buf))
+ if (SAFE_STAT (".", &stat_buf))
error (1, errno, "current directory");
initial_ino = stat_buf.st_ino;
initial_dev = stat_buf.st_dev;
@@ -365,7 +364,7 @@ du_files (files)
count_entry (arg, 1, 0);
/* chdir if `count_entry' has changed the working directory. */
- if (stat (".", &stat_buf))
+ if (SAFE_STAT (".", &stat_buf))
error (1, errno, ".");
if ((stat_buf.st_ino != initial_ino || stat_buf.st_dev != initial_dev)
&& chdir (wd) < 0)
@@ -396,7 +395,7 @@ count_entry (ent, top, last_dev)
long size;
if (((top && opt_dereference_arguments)
- ? stat (ent, &stat_buf)
+ ? SAFE_STAT (ent, &stat_buf)
: (*xstat) (ent, &stat_buf)) < 0)
{
error (0, errno, "%s", path->text);
diff --git a/src/install.c b/src/install.c
index 77617b02a..ad5aef395 100644
--- a/src/install.c
+++ b/src/install.c
@@ -71,6 +71,7 @@
#include <grp.h>
#include "system.h"
#include "version.h"
+#include "safe-stat.h"
#include "modechange.h"
#if !defined (isascii) || defined (STDC_HEADERS)
@@ -332,7 +333,7 @@ copy_file (from, to, to_created)
struct stat from_stats, to_stats;
int target_created = 1;
- if (stat (from, &from_stats))
+ if (SAFE_STAT (from, &from_stats))
{
error (0, errno, "%s", from);
return 1;
@@ -342,7 +343,7 @@ copy_file (from, to, to_created)
error (0, 0, "`%s' is not a regular file", from);
return 1;
}
- if (stat (to, &to_stats) == 0)
+ if (SAFE_STAT (to, &to_stats) == 0)
{
if (!S_ISREG (to_stats.st_mode))
{
diff --git a/src/ln.c b/src/ln.c
index 21ba6aded..87f0a8c19 100644
--- a/src/ln.c
+++ b/src/ln.c
@@ -38,6 +38,7 @@
#include "system.h"
#include "backupfile.h"
#include "version.h"
+#include "safe-lstat.h"
int link (); /* Some systems don't declare this anywhere. */
@@ -223,7 +224,7 @@ main (argc, argv)
`ln source dest/' to `ln source dest/basename(source)'. */
if (dest[strlen (dest) - 1] == '/'
- && lstat (source, &source_stats) == 0
+ && SAFE_LSTAT (source, &source_stats) == 0
&& !S_ISDIR (source_stats.st_mode))
{
PATH_BASENAME_CONCAT (new_dest, dest, source);
@@ -278,7 +279,7 @@ do_link (source, dest)
dest = new_dest;
}
- if (lstat (dest, &dest_stats) == 0)
+ if (SAFE_LSTAT (dest, &dest_stats) == 0)
{
if (S_ISDIR (dest_stats.st_mode))
{
diff --git a/src/ls.c b/src/ls.c
index 06b9dae79..da0c1d66e 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -60,6 +60,8 @@
#include "ls.h"
#include "version.h"
+#include "safe-stat.h"
+#include "safe-lstat.h"
#ifndef S_IEXEC
#define S_IEXEC S_IXUSR
@@ -992,14 +994,14 @@ gobble_file (name, explicit_arg, dirname)
if (trace_links)
{
- val = stat (path, &files[files_index].stat);
+ val = SAFE_STAT (path, &files[files_index].stat);
if (val < 0)
/* Perhaps a symbolically-linked to file doesn't exist; stat
the link instead. */
- val = lstat (path, &files[files_index].stat);
+ val = SAFE_LSTAT (path, &files[files_index].stat);
}
else
- val = lstat (path, &files[files_index].stat);
+ val = SAFE_LSTAT (path, &files[files_index].stat);
if (val < 0)
{
error (0, errno, "%s", path);
@@ -1022,7 +1024,7 @@ gobble_file (name, explicit_arg, dirname)
if (linkpath
&& ((explicit_arg && format != long_format)
|| indicator_style != none)
- && stat (linkpath, &linkstats) == 0)
+ && SAFE_STAT (linkpath, &linkstats) == 0)
{
/* Symbolic links to directories that are mentioned on the
command line are automatically traced if not being
diff --git a/src/mv.c b/src/mv.c
index e56a6eb23..1b6664557 100644
--- a/src/mv.c
+++ b/src/mv.c
@@ -58,6 +58,7 @@
#include "system.h"
#include "backupfile.h"
#include "version.h"
+#include "safe-lstat.h"
#ifndef _POSIX_VERSION
uid_t geteuid ();
@@ -214,7 +215,7 @@ is_real_dir (path)
{
struct stat stats;
- return lstat (path, &stats) == 0 && S_ISDIR (stats.st_mode);
+ return SAFE_LSTAT (path, &stats) == 0 && S_ISDIR (stats.st_mode);
}
/* Move file SOURCE onto DEST. Handles the case when DEST is a directory.
@@ -256,13 +257,13 @@ do_move (source, dest)
{
char *dest_backup = NULL;
- if (lstat (source, &source_stats) != 0)
+ if (SAFE_LSTAT (source, &source_stats) != 0)
{
error (0, errno, "%s", source);
return 1;
}
- if (lstat (dest, &dest_stats) == 0)
+ if (SAFE_LSTAT (dest, &dest_stats) == 0)
{
if (source_stats.st_dev == dest_stats.st_dev
&& source_stats.st_ino == dest_stats.st_ino)
diff --git a/src/rm.c b/src/rm.c
index 1365e6656..438e8fa42 100644
--- a/src/rm.c
+++ b/src/rm.c
@@ -33,6 +33,7 @@
#include <sys/types.h>
#include "system.h"
#include "version.h"
+#include "safe-lstat.h"
#ifdef _POSIX_SOURCE
/* POSIX.1 doesn't have inodes, so fake them to avoid lots of ifdefs. */
@@ -205,7 +206,7 @@ rm ()
return 1;
}
- if (lstat (pathname, &path_stats))
+ if (SAFE_LSTAT (pathname, &path_stats))
{
if (errno == ENOENT && ignore_missing_files)
return 0;
diff --git a/src/touch.c b/src/touch.c
index 33fadc282..feadcc713 100644
--- a/src/touch.c
+++ b/src/touch.c
@@ -49,6 +49,7 @@
#include <sys/types.h>
#include "system.h"
#include "version.h"
+#include "safe-stat.h"
#ifndef STDC_HEADERS
time_t mktime ();
@@ -227,7 +228,7 @@ main (argc, argv)
if (use_ref)
{
- if (stat (ref_file, &ref_stats))
+ if (SAFE_STAT (ref_file, &ref_stats))
error (1, errno, "%s", ref_file);
date_set++;
}
@@ -272,7 +273,7 @@ touch (file)
struct stat sbuf;
int fd;
- if (stat (file, &sbuf))
+ if (SAFE_STAT (file, &sbuf))
{
if (errno != ENOENT)
{