svn commit: r217299 - stable/7/usr.bin/stat
Doug Barton
dougb at FreeBSD.org
Wed Jan 12 07:27:30 UTC 2011
Author: dougb
Date: Wed Jan 12 07:27:30 2011
New Revision: 217299
URL: http://svn.freebsd.org/changeset/base/217299
Log:
MFC r188498 (partial):
"I've changed main() to set file properly, so output() is never called
with file set to NULL."
Obtained from: ed
The other bits of that revision are related to using fdevname(3).
This was never merged back to RELENG_7, however the cleanup of
the code in this MFC is good both for general purposes, and diff
reduction to HEAD (which in turn will make the following MFCs easier).
Modified:
stable/7/usr.bin/stat/stat.c
Directory Properties:
stable/7/usr.bin/stat/ (props changed)
Modified: stable/7/usr.bin/stat/stat.c
==============================================================================
--- stable/7/usr.bin/stat/stat.c Wed Jan 12 05:37:13 2011 (r217298)
+++ stable/7/usr.bin/stat/stat.c Wed Jan 12 07:27:30 2011 (r217299)
@@ -200,6 +200,7 @@ main(int argc, char *argv[])
int ch, rc, errs, am_readlink;
int lsF, fmtchar, usestat, fn, nonl, quiet;
char *statfmt, *options, *synopsis;
+ const char *file;
am_readlink = 0;
lsF = 0;
@@ -300,22 +301,25 @@ main(int argc, char *argv[])
errs = 0;
do {
- if (argc == 0)
+ if (argc == 0) {
+ file = "(stdin)";
rc = fstat(STDIN_FILENO, &st);
- else if (usestat)
- rc = stat(argv[0], &st);
- else
- rc = lstat(argv[0], &st);
+ } else {
+ file = argv[0];
+ if (usestat)
+ rc = stat(file, &st);
+ else
+ rc = lstat(file, &st);
+ }
if (rc == -1) {
errs = 1;
linkfail = 1;
if (!quiet)
- warn("%s: stat",
- argc == 0 ? "(stdin)" : argv[0]);
+ warn("%s: stat", file);
}
else
- output(&st, argv[0], statfmt, fn, nonl, quiet);
+ output(&st, file, statfmt, fn, nonl, quiet);
argv++;
argc--;
@@ -828,10 +832,7 @@ format1(const struct stat *st,
case SHOW_filename:
small = 0;
data = 0;
- if (file == NULL)
- (void)strncpy(path, "(stdin)", sizeof(path));
- else
- (void)strncpy(path, file, sizeof(path));
+ (void)strncpy(path, file, sizeof(path));
sdata = path;
formats = FMTF_STRING;
if (ofmt == 0)
More information about the svn-src-all
mailing list