diff options
Diffstat (limited to 'udfinfo/options.c')
-rw-r--r-- | udfinfo/options.c | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/udfinfo/options.c b/udfinfo/options.c index fbc6a95..de93e38 100644 --- a/udfinfo/options.c +++ b/udfinfo/options.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Pali Rohár <pali.rohar@gmail.com> + * Copyright (C) 2017-2018 Pali Rohár <pali.rohar@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,19 +48,8 @@ static void usage(void) exit(1); } -static unsigned long int strtoul_safe(const char *str, int base, int *failed) -{ - char *endptr = NULL; - unsigned long int ret; - errno = 0; - ret = strtoul(str, &endptr, base); - *failed = (!*str || *endptr || errno) ? 1 : 0; - return ret; -} - void parse_args(int argc, char *argv[], struct udf_disc *disc, char **filename) { - unsigned long int value; int failed; int ret; @@ -74,22 +63,20 @@ void parse_args(int argc, char *argv[], struct udf_disc *disc, char **filename) break; case OPT_BLK_SIZE: case 'b': - value = strtoul_safe(optarg, 0, &failed); - if (failed || value < 512 || value > 32768 || (value & (value - 1))) + disc->blocksize = strtou32(optarg, 0, &failed); + if (failed || disc->blocksize < 512 || disc->blocksize > 32768 || (disc->blocksize & (disc->blocksize - 1))) { fprintf(stderr, "%s: Error: Invalid value for option --blocksize\n", appname); exit(1); } - disc->blocksize = value; break; case OPT_VAT_BLOCK: - value = strtoul_safe(optarg, 0, &failed); - if (failed || value > UINT32_MAX) + disc->vat_block = strtou32(optarg, 0, &failed); + if (failed) { fprintf(stderr, "%s: Error: Invalid value for option --vatblock\n", appname); exit(1); } - disc->vat_block = value; break; case OPT_UNICODE8: disc->flags &= ~FLAG_CHARSET; |