[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug#158957: fileutils: stat does not return errors
From: |
Jim Meyering |
Subject: |
Re: Bug#158957: fileutils: stat does not return errors |
Date: |
Wed, 08 Sep 2004 15:54:38 +0200 |
Andreas Metzler <address@hidden> wrote:
> On 2002-09-01 Michael Stone <address@hidden> wrote:
>> On Sat, Aug 31, 2002 at 03:24:24PM +1000, you wrote:
>>> $ stat a
>>> stat: cannot stat `a': No such file or directory
>>> $ echo $?
>>> 0
That sure looks like a bug to me.
Thanks for reporting it.
Here's a patch:
2004-09-08 Jim Meyering <address@hidden>
* src/stat.c (G_fail): Remove unused global.
(do_stat, do_statfs): Change return type to `bool' and return
an indication of success. Adjust callers.
Index: src/stat.c
===================================================================
RCS file: /fetish/cu/src/stat.c,v
retrieving revision 1.72
diff -u -p -r1.72 stat.c
--- src/stat.c 30 Jun 2004 22:31:43 -0000 1.72
+++ src/stat.c 8 Sep 2004 13:50:10 -0000
@@ -102,9 +102,6 @@ static struct option const long_options[
{NULL, 0, NULL, 0}
};
-/* Nonzero means we should exit with EXIT_FAILURE upon completion. */
-static int G_fail;
-
char *program_name;
/* Return the type of the specified file system.
@@ -613,8 +610,9 @@ print_it (char const *masterformat, char
free (dest);
}
-/* Stat the file system and print what we find. */
-static void
+/* Stat the file system and print what we find.
+ Return false if stat fails, otherwise return true. */
+static bool
do_statfs (char const *filename, int terse, char const *format)
{
STRUCT_STATVFS statfsbuf;
@@ -624,7 +622,7 @@ do_statfs (char const *filename, int ter
{
error (0, errno, _("cannot read file system information for %s"),
quote (filename));
- return;
+ return false;
}
if (format == NULL)
@@ -638,10 +636,12 @@ do_statfs (char const *filename, int ter
}
print_it (format, filename, print_statfs, &statfsbuf);
+ return true;
}
-/* stat the file and print what we find */
-static void
+/* Stat the file and print what we find.
+ Return false if stat fails, otherwise return true. */
+static bool
do_stat (char const *filename, int follow_links, int terse,
char const *format)
{
@@ -653,7 +653,7 @@ do_stat (char const *filename, int follo
if (i == -1)
{
error (0, errno, _("cannot stat %s"), quote (filename));
- return;
+ return false;
}
if (format == NULL)
@@ -688,6 +688,7 @@ do_stat (char const *filename, int follo
}
}
print_it (format, filename, print_stat, &statbuf);
+ return true;
}
void
@@ -826,13 +827,16 @@ main (int argc, char *argv[])
usage (EXIT_FAILURE);
}
- for (i = optind; i < argc; i++)
- {
- if (fs == 0)
- do_stat (argv[i], follow_links, terse, format);
- else
- do_statfs (argv[i], terse, format);
- }
+ { /* FIXME-c99: remove these braces */
+ bool fail = false;
+ for (i = optind; i < argc; i++)
+ {
+ if (fs == 0)
+ fail |= !do_stat (argv[i], follow_links, terse, format);
+ else
+ fail |= !do_statfs (argv[i], terse, format);
+ }
- exit (G_fail ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit (fail ? EXIT_FAILURE : EXIT_SUCCESS);
+ }
}
- Re: Bug#158957: fileutils: stat does not return errors,
Jim Meyering <=