public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 11/13] vipw: add usage() function
Date: Tue,  2 Apr 2013 20:42:55 +0100	[thread overview]
Message-ID: <1364931777-2645-12-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1364931777-2645-1-git-send-email-kerolasa@iki.fi>

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 login-utils/vipw.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/login-utils/vipw.c b/login-utils/vipw.c
index 8c47801..6ca5f8c 100644
--- a/login-utils/vipw.c
+++ b/login-utils/vipw.c
@@ -302,6 +302,17 @@ static void edit_file(int is_shadow)
 	ulckpwdf();
 }
 
+static void __attribute__((__noreturn__)) usage(FILE *out)
+{
+	fputs(USAGE_HEADER, out);
+	fprintf(out, " %s\n", program_invocation_short_name);
+	fputs(USAGE_OPTIONS, out);
+	fputs(USAGE_HELP, out);
+	fputs(USAGE_VERSION, out);
+	fprintf(out, USAGE_MAN_TAIL("vipw(8)"));
+	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
 int main(int argc, char *argv[])
 {
 	setlocale(LC_ALL, "");
@@ -317,10 +328,14 @@ int main(int argc, char *argv[])
 		xstrncpy(orig_file, PASSWD_FILE, sizeof(orig_file));
 	}
 
-	if ((argc > 1) &&
-	    (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
-		printf(UTIL_LINUX_VERSION);
-		exit(EXIT_SUCCESS);
+	if (1 < argc) {
+		if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
+			printf(UTIL_LINUX_VERSION);
+			exit(EXIT_SUCCESS);
+		}
+		if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
+			usage(stdout);
+		usage(stderr);
 	}
 
 	edit_file(0);
-- 
1.8.2


  parent reply	other threads:[~2013-04-02 19:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-02 19:42 [PATCH 00/13] pull: fixes in preparation to v2.23 release Sami Kerola
2013-04-02 19:42 ` [PATCH 01/13] docs: fix type in mkfs.8 Sami Kerola
2013-04-02 19:42 ` [PATCH 02/13] newgrp: use xstrdup to check allocation succeeded Sami Kerola
2013-04-02 19:42 ` [PATCH 03/13] agetty: the command does not have -h and -V options Sami Kerola
2013-04-02 19:42 ` [PATCH 04/13] dmesg: fix usage() output consistancy Sami Kerola
2013-04-02 19:42 ` [PATCH 05/13] fsfreeze: tell user when mandatory option is not specified Sami Kerola
2013-04-02 19:42 ` [PATCH 06/13] losetup: allow -j option argument to be relative path Sami Kerola
2013-04-02 19:42 ` [PATCH 07/13] lscpu: fix error message Sami Kerola
2013-04-02 19:42 ` [PATCH 08/13] partx: remove deprecated option from usage() Sami Kerola
2013-04-02 19:42 ` [PATCH 09/13] setarch: add option to list settable architectures Sami Kerola
2013-04-05 12:04   ` Karel Zak
2013-04-02 19:42 ` [PATCH 10/13] setterm: fix various color option argument lists Sami Kerola
2013-04-02 19:42 ` Sami Kerola [this message]
2013-04-02 19:42 ` [PATCH 12/13] chrt: make command syntax easier to understand in usage() Sami Kerola
2013-04-02 19:42 ` [PATCH 13/13] logger: make local sockets to try both stream and datagram Sami Kerola
2013-04-05 12:10 ` [PATCH 00/13] pull: fixes in preparation to v2.23 release Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1364931777-2645-12-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox