diff mbox

[U-Boot,2/4] mkenvimage: Fix getopt() error handling

Message ID 1323082526-2125-2-git-send-email-hkronsto@frequentis.com
State Accepted
Commit 5e0c63e2e3e7a0aefb01d877dd7bb731ba6f00f1
Headers show

Commit Message

Horst Kronstorfer Dec. 5, 2011, 10:55 a.m. UTC
Since the original implementation indicates explicit error handling
we turn off getopt()'s internal error messaging to avoid duplicate
error messages.  Additionally we add ':' (missing option argument)
error handling.

Signed-off-by: Horst Kronstorfer <hkronsto@frequentis.com>
---
 tools/mkenvimage.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

Comments

Wolfgang Denk Dec. 20, 2011, 10:51 p.m. UTC | #1
Dear Horst Kronstorfer,

In message <1323082526-2125-2-git-send-email-hkronsto@frequentis.com> you wrote:
> Since the original implementation indicates explicit error handling
> we turn off getopt()'s internal error messaging to avoid duplicate
> error messages.  Additionally we add ':' (missing option argument)
> error handling.
> 
> Signed-off-by: Horst Kronstorfer <hkronsto@frequentis.com>
> ---
>  tools/mkenvimage.c |   12 ++++++++++--
>  1 files changed, 10 insertions(+), 2 deletions(-)

Applied to "next" branch, thanks.

Best regards,

Wolfgang Denk
diff mbox

Patch

diff --git a/tools/mkenvimage.c b/tools/mkenvimage.c
index b7b0e0f..22d1b88 100644
--- a/tools/mkenvimage.c
+++ b/tools/mkenvimage.c
@@ -80,8 +80,11 @@  int main(int argc, char **argv)
 
 	int fp, ep;
 
+	/* Turn off getopt()'s internal error message */
+	opterr = 0;
+
 	/* Parse the cmdline */
-	while ((option = getopt(argc, argv, "s:o:rbp:h")) != -1) {
+	while ((option = getopt(argc, argv, ":s:o:rbp:h")) != -1) {
 		switch (option) {
 		case 's':
 			datasize = strtol(optarg, NULL, 0);
@@ -106,8 +109,13 @@  int main(int argc, char **argv)
 		case 'h':
 			usage(argv[0]);
 			return EXIT_SUCCESS;
+		case ':':
+			fprintf(stderr, "Missing argument for option -%c\n",
+				optopt);
+			usage(argv[0]);
+			return EXIT_FAILURE;
 		default:
-			fprintf(stderr, "Wrong option -%c\n", option);
+			fprintf(stderr, "Wrong option -%c\n", optopt);
 			usage(argv[0]);
 			return EXIT_FAILURE;
 		}