]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
.
authorJim Meyering <jim@meyering.net>
Sat, 30 Jul 1994 16:34:17 +0000 (16:34 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 30 Jul 1994 16:34:17 +0000 (16:34 +0000)
src/df.c
src/du.c
src/install.c
src/ln.c
src/ls.c
src/mv.c
src/rm.c
src/touch.c

index 956c9d6754786dc1551f233095788db2c441861d..c1457bc35f86454f6881cd5b041e84722c5f5b0f 100644 (file)
--- 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
            {
index b3a9a83ef7c80c8bb955199ca96ee4473fddd23a..b53775a817b8dfee6d8f16c5185995e9ba7d74cb 100644 (file)
--- 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);
index 77617b02ad0ec5078a33256cad5ba3050c552cd3..ad5aef3955e498c83db36ff65a4e4fe471ac564d 100644 (file)
@@ -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))
        {
index 21ba6aded2843fa04be90e5be5fbb49cee313c82..87f0a8c19be6a3fd7d5a8d10f762198072d5705a 100644 (file)
--- 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))
        {
index 06b9dae799de7be3a5fd3ff318c24700648345e3..da0c1d66e0c9db984aa139706324490451d04194 100644 (file)
--- 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
index e56a6eb231cb07bc9c5b695324c5defe299b48ed..1b6664557f08fa4623e58c5872c3c3953337f352 100644 (file)
--- 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)
index 1365e665632e520ad4dd9f78f912635a8125016d..438e8fa426dc20b40b57c5f761eea276c89c392f 100644 (file)
--- 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;
index 33fadc2822c3c6808bad1fe6265c88d42c44bbea..feadcc71353eb6a85b7323745ca47bbe65dcdaa9 100644 (file)
@@ -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)
        {