diff options
author | G. Branden Robinson <g.branden.robinson@gmail.com> | 2022-10-24 11:52:17 -0500 |
---|---|---|
committer | G. Branden Robinson <g.branden.robinson@gmail.com> | 2022-10-29 12:52:02 -0500 |
commit | 8ad4f0ad75f5a63d945e9f3f865b691fa56df484 (patch) | |
tree | 7ddebb4ee677a226ba33a5c0eeb5508e797eefd3 /src/utils | |
parent | 52350eb1debd7df586bbb478bc3faed80d79f8e0 (diff) | |
download | groff-git-8ad4f0ad75f5a63d945e9f3f865b691fa56df484.tar.gz |
[pfbtops]: Fix code style and diagnostic nits.
* src/utils/pfbtops/pfbtops.c (error): Exit with `EXIT_FAILURE` status
(from standard C library) instead of status 2.
(main): Exit with `EXIT_SUCCESS` status when writing version or help
information. Exit with status 2 when dying due to usage error. Use
`fprintf()` and `strerror()` to construct error message when dying due
to inability to open input file instead of using `perror()`, which
anonymizes its caller and thus should never be used in serious work.
Avoid it like `gets()`.
* NEWS: Add item for exit status changes.
Continues the long process of fixing Savannah #52463.
Also update editor aid comments.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/pfbtops/pfbtops.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/utils/pfbtops/pfbtops.c b/src/utils/pfbtops/pfbtops.c index 81edee422..8fbe44a79 100644 --- a/src/utils/pfbtops/pfbtops.c +++ b/src/utils/pfbtops/pfbtops.c @@ -24,8 +24,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #define __GETOPT_PREFIX groff_ +#include <errno.h> // errno #include <stdio.h> -#include <stdlib.h> +#include <stdlib.h> // exit(), EXIT_FAILURE, EXIT_SUCCESS +#include <string.h> // strerror() #include <limits.h> #include <getopt.h> @@ -43,8 +45,8 @@ static char *program_name; static void error(const char *s) { - fprintf(stderr, "%s: %s\n", program_name, s); - exit(2); + fprintf(stderr, "%s: error: %s\n", program_name, s); + exit(EXIT_FAILURE); } static void usage(FILE *stream) @@ -181,26 +183,28 @@ int main(int argc, char **argv) switch (opt) { case 'v': printf("GNU pfbtops (groff) version %s\n", Version_string); - exit(0); + exit(EXIT_SUCCESS); break; case CHAR_MAX + 1: /* --help */ usage(stdout); - exit(0); + exit(EXIT_SUCCESS); break; case '?': usage(stderr); - exit(1); + exit(2); break; } } if (argc - optind > 1) { usage(stderr); - exit(1); + exit(2); } - if (argc > optind && !freopen(argv[optind], "r", stdin)) { - perror(argv[optind]); - exit(1); + const char *file = argv[optind]; + if (argc > optind && !freopen(file, "r", stdin)) { + fprintf(stderr, "%s: error: unable to open file '%s': %s\n", + program_name, file, strerror(errno)); + exit(EXIT_FAILURE); } SET_BINARY(fileno(stdin)); for (;;) { @@ -229,5 +233,11 @@ int main(int argc, char **argv) else get_binary(n); } - exit(0); + exit(EXIT_SUCCESS); } + +// Local Variables: +// fill-column: 72 +// mode: C +// End: +// vim: set cindent noexpandtab shiftwidth=2 textwidth=72: |