#include "fsusage.h"
#include "system.h"
#include "version.h"
+#include "safe-stat.h"
char *xmalloc ();
char *xstrdup ();
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;
{
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
{
#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
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))
break;
case 'L':
- xstat = stat;
+ xstat = safe_stat;
break;
case 'S':
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;
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)
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);
#include <grp.h>
#include "system.h"
#include "version.h"
+#include "safe-stat.h"
#include "modechange.h"
#if !defined (isascii) || defined (STDC_HEADERS)
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;
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))
{
#include "system.h"
#include "backupfile.h"
#include "version.h"
+#include "safe-lstat.h"
int link (); /* Some systems don't declare this anywhere. */
`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);
dest = new_dest;
}
- if (lstat (dest, &dest_stats) == 0)
+ if (SAFE_LSTAT (dest, &dest_stats) == 0)
{
if (S_ISDIR (dest_stats.st_mode))
{
#include "ls.h"
#include "version.h"
+#include "safe-stat.h"
+#include "safe-lstat.h"
#ifndef S_IEXEC
#define S_IEXEC S_IXUSR
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);
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
#include "system.h"
#include "backupfile.h"
#include "version.h"
+#include "safe-lstat.h"
#ifndef _POSIX_VERSION
uid_t geteuid ();
{
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.
{
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)
#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. */
return 1;
}
- if (lstat (pathname, &path_stats))
+ if (SAFE_LSTAT (pathname, &path_stats))
{
if (errno == ENOENT && ignore_missing_files)
return 0;
#include <sys/types.h>
#include "system.h"
#include "version.h"
+#include "safe-stat.h"
#ifndef STDC_HEADERS
time_t mktime ();
if (use_ref)
{
- if (stat (ref_file, &ref_stats))
+ if (SAFE_STAT (ref_file, &ref_stats))
error (1, errno, "%s", ref_file);
date_set++;
}
struct stat sbuf;
int fd;
- if (stat (file, &sbuf))
+ if (SAFE_STAT (file, &sbuf))
{
if (errno != ENOENT)
{