]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
mkenvimage: Fix getopt() error handling
authorHorst Kronstorfer <hkronsto@frequentis.com>
Mon, 5 Dec 2011 00:55:24 +0000 (00:55 +0000)
committerWolfgang Denk <wd@denx.de>
Tue, 20 Dec 2011 22:51:36 +0000 (23:51 +0100)
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

index b7b0e0fade0f8252bfcda5f671103c6002386c51..22d1b88ba2fb02e410e5f09261f794499897b807 100644 (file)
@@ -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;
                }