diff options
author | delphij <delphij@FreeBSD.org> | 2005-01-26 15:17:25 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2005-01-26 15:17:25 +0000 |
commit | ee377142a374dc56fcb73ee5562f5d9de50a6225 (patch) | |
tree | 5beaea97e0ad5cc5cdc8d278f71e78c80dfa009a /usr.bin/fsync | |
parent | 3ff9202b440bbffe0c76d04a1f985f6d1023b3b7 (diff) | |
download | FreeBSD-src-ee377142a374dc56fcb73ee5562f5d9de50a6225.zip FreeBSD-src-ee377142a374dc56fcb73ee5562f5d9de50a6225.tar.gz |
Correct some style nits that I have mistakenly submitted as
suggestions which result in the last revision[*]:
- style(9) and sysexits(3) suggests that we use EX_*
as exit values, instead of some other values like
those returned from a system call as errno.
Additionally, follow Ruslan's suggestion about style(9) and
other style improvements:
- Since open(2) says that it returns -1 on errors,
explicitly determine whether it is returning -1
rather than whether the return value is less than
zero.
- Only set rval when there is no previous error.
This distinguishes the first error that occours.
- Use exit() in favor of return in main(), this is
suggested in old style(9), while the evolve has
fade the suggestion.
- Add some NOTREACHED comments.
- Add blank line after first { because no local variables
in usage()
Thanks to Ruslan for his tireless explaining of the code standards
and knowledge of the history of style(9).
[*] Pointy hat to: me
Submitted by: ru (with some minor changes)
Discussed with: ru, ssouhlal
Diffstat (limited to 'usr.bin/fsync')
-rw-r--r-- | usr.bin/fsync/fsync.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/usr.bin/fsync/fsync.c b/usr.bin/fsync/fsync.c index 543356f..78aeb21 100644 --- a/usr.bin/fsync/fsync.c +++ b/usr.bin/fsync/fsync.c @@ -30,7 +30,6 @@ __FBSDID("$FreeBSD$"); #include <err.h> -#include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> @@ -46,29 +45,36 @@ main(int argc, char *argv[]) int i; int rval; - if (argc < 2) + if (argc < 2) { usage(); + /* NOTREACHED */ + } - rval = 0; + rval = EX_OK; for (i = 1; i < argc; ++i) { - if ((fd = open(argv[i], O_RDONLY)) < 0) { + if ((fd = open(argv[i], O_RDONLY)) == -1) { warn("open %s", argv[i]); - rval = errno; + if (rval == EX_OK) + rval = EX_NOINPUT; continue; } - if (fsync(fd) != 0) { + if (fsync(fd) == -1) { warn("fsync %s", argv[i]); - rval = errno; + if (rval == EX_OK) + rval = EX_OSERR; } close(fd); } - return (rval); + exit(rval); + /* NOTREACHED */ } static void -usage() +usage(void) { + fprintf(stderr, "usage: fsync file ...\n"); exit(EX_USAGE); + /* NOTREACHED */ } |