aboutsummaryrefslogtreecommitdiff
path: root/mkfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-23 00:41:22 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-23 00:41:22 +0200
commit5f7a1a092495c84c4c4cd208c3c983c3f16c8951 (patch)
tree98c0a33c51ab5727e00b18488dd5fb97af763e77 /mkfs
parent3c944ece469440557b53e65c82e4e574f7077627 (diff)
gensquashfs: remove command line number parsing code
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'mkfs')
-rw-r--r--mkfs/options.c54
1 files changed, 7 insertions, 47 deletions
diff --git a/mkfs/options.c b/mkfs/options.c
index ff7766c..a746ba4 100644
--- a/mkfs/options.c
+++ b/mkfs/options.c
@@ -137,59 +137,19 @@ static const char *compressors[] = {
static long read_number(const char *name, const char *str, long min, long max)
{
- long base = 10, result = 0;
- int x;
+ long result = strtol(str, NULL, 0);
- if (str[0] == '0') {
- if (str[1] == 'x' || str[1] == 'X') {
- base = 16;
- str += 2;
- } else {
- base = 8;
- }
+ if (result < min) {
+ fprintf(stderr, "%s: number too small\n", name);
+ exit(EXIT_FAILURE);
}
- if (!isxdigit(*str))
- goto fail_num;
-
- while (isxdigit(*str)) {
- x = *(str++);
-
- if (isupper(x)) {
- x = x - 'A' + 10;
- } else if (islower(x)) {
- x = x - 'a' + 10;
- } else {
- x -= '0';
- }
-
- if (x >= base)
- goto fail_num;
-
- if (result > (LONG_MAX - x) / base)
- goto fail_ov;
-
- result = result * base + x;
+ if (result > max) {
+ fprintf(stderr, "%s: number too large\n", name);
+ exit(EXIT_FAILURE);
}
- if (result < min)
- goto fail_uf;
-
- if (result > max)
- goto fail_ov;
-
return result;
-fail_num:
- fprintf(stderr, "%s: expected numeric value > 0\n", name);
- goto fail;
-fail_uf:
- fprintf(stderr, "%s: number to small\n", name);
- goto fail;
-fail_ov:
- fprintf(stderr, "%s: number to large\n", name);
- goto fail;
-fail:
- exit(EXIT_FAILURE);
}
static void process_defaults(options_t *opt, char *subopts)