mkenvimage: Fix getopt() error handling
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>
This commit is contained in:
parent
d30011bf61
commit
5e0c63e2e3
|
@ -80,8 +80,11 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
int fp, ep;
|
int fp, ep;
|
||||||
|
|
||||||
|
/* Turn off getopt()'s internal error message */
|
||||||
|
opterr = 0;
|
||||||
|
|
||||||
/* Parse the cmdline */
|
/* 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) {
|
switch (option) {
|
||||||
case 's':
|
case 's':
|
||||||
datasize = strtol(optarg, NULL, 0);
|
datasize = strtol(optarg, NULL, 0);
|
||||||
|
@ -106,8 +109,13 @@ int main(int argc, char **argv)
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
case ':':
|
||||||
|
fprintf(stderr, "Missing argument for option -%c\n",
|
||||||
|
optopt);
|
||||||
|
usage(argv[0]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Wrong option -%c\n", option);
|
fprintf(stderr, "Wrong option -%c\n", optopt);
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue