From 6e1eda6f229f87b77471ce6eb7cbf0ede7c8029e Mon Sep 17 00:00:00 2001 From: Ruediger Meier Date: Mon, 19 Jun 2017 20:52:50 +0200 Subject: misc: never use usage(stderr) Here we fix all cases where we have usage(FILE*) functions. Signed-off-by: Ruediger Meier --- sys-utils/tunelp.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'sys-utils/tunelp.c') diff --git a/sys-utils/tunelp.c b/sys-utils/tunelp.c index 2749dd1c8..99da3f3f6 100644 --- a/sys-utils/tunelp.c +++ b/sys-utils/tunelp.c @@ -87,8 +87,9 @@ struct command { struct command *next; }; -static void __attribute__((__noreturn__)) print_usage(FILE *out) +static void __attribute__((__noreturn__)) usage(void) { + FILE *out = stdout; fputs(USAGE_HEADER, out); fprintf(out, _(" %s [options] \n"), program_invocation_short_name); @@ -115,7 +116,7 @@ static void __attribute__((__noreturn__)) print_usage(FILE *out) fputs(USAGE_VERSION, out); fprintf(out, USAGE_MAN_TAIL("tunelp(8)")); - exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); + exit(EXIT_SUCCESS); } int main(int argc, char **argv) @@ -148,8 +149,10 @@ int main(int argc, char **argv) strutils_set_exitcode(EXIT_LP_BADVAL); - if (argc < 2) - print_usage(stderr); + if (argc < 2) { + warnx(_("not enough arguments")); + errtryhelp(EXIT_FAILURE); + } cmdst = cmds = xmalloc(sizeof(struct command)); cmds->next = NULL; @@ -158,7 +161,7 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, "t:c:w:a:i:ho:C:sq:rT:vV", longopts, NULL)) != -1) { switch (c) { case 'h': - print_usage(stdout); + usage(); break; case 'i': cmds->op = LPSETIRQ; @@ -246,8 +249,10 @@ int main(int argc, char **argv) } } - if (optind != argc - 1) - print_usage(stderr); + if (optind != argc - 1) { + warnx(_("no device specified")); + errtryhelp(EXIT_FAILURE); + } filename = xstrdup(argv[optind]); fd = open(filename, O_WRONLY | O_NONBLOCK, 0); @@ -263,7 +268,7 @@ int main(int argc, char **argv) if (!S_ISCHR(statbuf.st_mode)) { warnx(_("%s not an lp device"), filename); - print_usage(stderr); + errtryhelp(EXIT_FAILURE); } /* Allow for binaries compiled under a new kernel to work on * the old ones The irq argument to ioctl isn't touched by -- cgit v1.2.3-55-g7522