]> www.infradead.org Git - mtd-utils.git/commitdiff
mtd-utils: switch ubi and ubifs tools to use common strtoX funcs
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Fri, 8 Apr 2011 14:58:55 +0000 (17:58 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Sat, 9 Apr 2011 14:49:22 +0000 (17:49 +0300)
Instead of using strtol and Co directly, use our share simple_strtoX()
helpers. This is just a cleanup.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
ubi-utils/src/mtdinfo.c
ubi-utils/src/ubiattach.c
ubi-utils/src/ubidetach.c
ubi-utils/src/ubiformat.c
ubi-utils/src/ubimkvol.c
ubi-utils/src/ubinfo.c
ubi-utils/src/ubinize.c
ubi-utils/src/ubirmvol.c
ubi-utils/src/ubirsvol.c
ubi-utils/src/ubiupdatevol.c

index 54a039a19c2d1a928ad1cb4903d0b9f2ad0db526..c9f6f589500d8bce8cda05e9a9c9b7428d4bcee9 100644 (file)
@@ -87,8 +87,7 @@ static const struct option long_options[] = {
 static int parse_opt(int argc, char * const argv[])
 {
        while (1) {
-               int key;
-               char *endp;
+               int key, error = 0;
 
                key = getopt_long(argc, argv, "am:uhV", long_options, NULL);
                if (key == -1)
@@ -104,8 +103,8 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 'm':
-                       args.mtdn = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.mtdn < 0)
+                       args.mtdn = simple_strtoul(optarg, &error);
+                       if (error || args.mtdn < 0)
                                return errmsg("bad MTD device number: \"%s\"", optarg);
 
                        break;
index d2f191bf151c10f160e7b1f70232991e8ca53337..9297b56d2f28b5cef8cd3d94c191e926553128ce 100644 (file)
@@ -91,8 +91,7 @@ static const struct option long_options[] = {
 static int parse_opt(int argc, char * const argv[])
 {
        while (1) {
-               int key;
-               char *endp;
+               int key, error = 0;
 
                key = getopt_long(argc, argv, "p:m:d:O:hV", long_options, NULL);
                if (key == -1)
@@ -103,22 +102,22 @@ static int parse_opt(int argc, char * const argv[])
                        args.dev = optarg;
                        break;
                case 'd':
-                       args.devn = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.devn < 0)
+                       args.devn = simple_strtoul(optarg, &error);
+                       if (error || args.devn < 0)
                                return errmsg("bad UBI device number: \"%s\"", optarg);
 
                        break;
 
                case 'm':
-                       args.mtdn = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.mtdn < 0)
+                       args.mtdn = simple_strtoul(optarg, &error);
+                       if (error || args.mtdn < 0)
                                return errmsg("bad MTD device number: \"%s\"", optarg);
 
                        break;
 
                case 'O':
-                       args.vidoffs = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.vidoffs <= 0)
+                       args.vidoffs = simple_strtoul(optarg, &error);
+                       if (error || args.vidoffs <= 0)
                                return errmsg("bad VID header offset: \"%s\"", optarg);
 
                        break;
index dfd64851c2ec7411e1cdba5452ac4f8c2618a83b..5ee55f1367fcaf58ab2d05eec7a28a2bebe3b0b7 100644 (file)
@@ -82,8 +82,7 @@ static const struct option long_options[] = {
 static int parse_opt(int argc, char * const argv[])
 {
        while (1) {
-               int key;
-               char *endp;
+               int key, error = 0;
 
                key = getopt_long(argc, argv, "p:m:d:hV", long_options, NULL);
                if (key == -1)
@@ -94,15 +93,15 @@ static int parse_opt(int argc, char * const argv[])
                        args.dev = optarg;
                        break;
                case 'd':
-                       args.devn = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.devn < 0)
+                       args.devn = simple_strtoul(optarg, &error);
+                       if (error || args.devn < 0)
                                return errmsg("bad UBI device number: \"%s\"", optarg);
 
                        break;
 
                case 'm':
-                       args.mtdn = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.mtdn < 0)
+                       args.mtdn = simple_strtoul(optarg, &error);
+                       if (error || args.mtdn < 0)
                                return errmsg("bad MTD device number: \"%s\"", optarg);
 
                        break;
index 098da7d251edbde66e13fd0e79bff2c17ca6696e..6e5cdb8cfc1981e8868a95e45c8f382f8c2aa8cb 100644 (file)
@@ -134,8 +134,7 @@ static int parse_opt(int argc, char * const argv[])
        args.image_seq = rand();
 
        while (1) {
-               int key;
-               char *endp;
+               int key, error = 0;
                unsigned long int image_seq;
 
                key = getopt_long(argc, argv, "nh?Vyqve:x:s:O:f:S:", long_options, NULL);
@@ -152,14 +151,14 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 'O':
-                       args.vid_hdr_offs = strtoul(optarg, &endp, 0);
-                       if (args.vid_hdr_offs <= 0 || *endp != '\0' || endp == optarg)
+                       args.vid_hdr_offs = simple_strtoul(optarg, &error);
+                       if (error || args.vid_hdr_offs <= 0)
                                return errmsg("bad VID header offset: \"%s\"", optarg);
                        break;
 
                case 'e':
-                       args.ec = strtoull(optarg, &endp, 0);
-                       if (args.ec < 0 || *endp != '\0' || endp == optarg)
+                       args.ec = simple_strtoull(optarg, &error);
+                       if (error || args.ec < 0)
                                return errmsg("bad erase counter value: \"%s\"", optarg);
                        if (args.ec >= EC_MAX)
                                return errmsg("too high erase %llu, counter, max is %u", args.ec, EC_MAX);
@@ -189,14 +188,14 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 'x':
-                       args.ubi_ver = strtoul(optarg, &endp, 0);
-                       if (args.ubi_ver < 0 || *endp != '\0' || endp == optarg)
+                       args.ubi_ver = simple_strtoul(optarg, &error);
+                       if (error || args.ubi_ver < 0)
                                return errmsg("bad UBI version: \"%s\"", optarg);
                        break;
 
                case 'Q':
-                       image_seq = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0'  || endp == optarg || image_seq > 0xFFFFFFFF)
+                       image_seq = simple_strtoul(optarg, &error);
+                       if (error || image_seq > 0xFFFFFFFF)
                                return errmsg("bad UBI image sequence number: \"%s\"", optarg);
                        args.image_seq = image_seq;
                        break;
index f6e498f7099bc8c58a2f08df916f16a825b24668..db71e2f8b8aa0f23702d9ec8187ef1b5a0b54df9 100644 (file)
@@ -121,8 +121,7 @@ static int param_sanity_check(void)
 static int parse_opt(int argc, char * const argv[])
 {
        while (1) {
-               int key;
-               char *endp;
+               int key, error = 1;
 
                key = getopt_long(argc, argv, "a:n:N:s:S:t:h?Vm", long_options, NULL);
                if (key == -1)
@@ -145,20 +144,20 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 'S':
-                       args.lebs = strtoull(optarg, &endp, 0);
-                       if (endp == optarg || args.lebs <= 0 || *endp != '\0')
+                       args.lebs = simple_strtoull(optarg, &error);
+                       if (error || args.lebs <= 0)
                                return errmsg("bad LEB count: \"%s\"", optarg);
                        break;
 
                case 'a':
-                       args.alignment = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.alignment <= 0)
+                       args.alignment = simple_strtoul(optarg, &error);
+                       if (error || args.alignment <= 0)
                                return errmsg("bad volume alignment: \"%s\"", optarg);
                        break;
 
                case 'n':
-                       args.vol_id = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.vol_id < 0)
+                       args.vol_id = simple_strtoul(optarg, &error);
+                       if (error || args.vol_id < 0)
                                return errmsg("bad volume ID: " "\"%s\"", optarg);
                        break;
 
index 3171e8a0dd39627956e23ae8694ca552402f9b2e..2bfee16c7ef8bd1bff151570ee0422a0d3d6a773 100644 (file)
@@ -89,8 +89,7 @@ static const struct option long_options[] = {
 static int parse_opt(int argc, char * const argv[])
 {
        while (1) {
-               int key;
-               char *endp;
+               int key, error = 0;
 
                key = getopt_long(argc, argv, "an:N:d:hV", long_options, NULL);
                if (key == -1)
@@ -102,8 +101,8 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 'n':
-                       args.vol_id = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.vol_id < 0)
+                       args.vol_id = simple_strtoul(optarg, &error);
+                       if (error || args.vol_id < 0)
                                return errmsg("bad volume ID: " "\"%s\"", optarg);
                        break;
 
@@ -112,8 +111,8 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 'd':
-                       args.devn = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.devn < 0)
+                       args.devn = simple_strtoul(optarg, &error);
+                       if (error || args.devn < 0)
                                return errmsg("bad UBI device number: \"%s\"", optarg);
 
                        break;
index 499169139c65c11d61528581b8a3ca7969f2a5cd..52a193f0d512413b1f997805e5bf1fe301e797e6 100644 (file)
@@ -159,8 +159,7 @@ static int parse_opt(int argc, char * const argv[])
        args.image_seq = rand();
 
        while (1) {
-               int key;
-               char *endp;
+               int key, error = 0;
                unsigned long int image_seq;
 
                key = getopt_long(argc, argv, "o:p:m:s:O:e:x:Q:vhV", long_options, NULL);
@@ -199,26 +198,26 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 'O':
-                       args.vid_hdr_offs = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.vid_hdr_offs < 0)
+                       args.vid_hdr_offs = simple_strtoul(optarg, &error);
+                       if (error || args.vid_hdr_offs < 0)
                                return errmsg("bad VID header offset: \"%s\"", optarg);
                        break;
 
                case 'e':
-                       args.ec = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.ec < 0)
+                       args.ec = simple_strtoul(optarg, &error);
+                       if (error || args.ec < 0)
                                return errmsg("bad erase counter value: \"%s\"", optarg);
                        break;
 
                case 'x':
-                       args.ubi_ver = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0'  || endp == optarg || args.ubi_ver < 0)
+                       args.ubi_ver = simple_strtoul(optarg, &error);
+                       if (error || args.ubi_ver < 0)
                                return errmsg("bad UBI version: \"%s\"", optarg);
                        break;
 
                case 'Q':
-                       image_seq = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0'  || endp == optarg || image_seq > 0xFFFFFFFF)
+                       image_seq = simple_strtoul(optarg, &error);
+                       if (error || image_seq > 0xFFFFFFFF)
                                return errmsg("bad UBI image sequence number: \"%s\"", optarg);
                        args.image_seq = image_seq;
                        break;
index 9e55b02279f8226f4b5693329c004aedc4f4d340..5a7217a4e511e65a70c5137514504c729ae018b1 100644 (file)
@@ -89,8 +89,7 @@ static int param_sanity_check(void)
 static int parse_opt(int argc, char * const argv[])
 {
        while (1) {
-               int key;
-               char *endp;
+               int key, error = 0;
 
                key = getopt_long(argc, argv, "n:N:h?V", long_options, NULL);
                if (key == -1)
@@ -99,8 +98,8 @@ static int parse_opt(int argc, char * const argv[])
                switch (key) {
 
                case 'n':
-                       args.vol_id = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.vol_id < 0) {
+                       args.vol_id = simple_strtoul(optarg, &error);
+                       if (error || args.vol_id < 0) {
                                errmsg("bad volume ID: " "\"%s\"", optarg);
                                return -1;
                        }
index 20a1d331493068a6fe15b94fd1c108d477d708db..34321b8ec0afe0bd096b9991d59fa04936caa693 100644 (file)
@@ -107,8 +107,7 @@ static int param_sanity_check(void)
 static int parse_opt(int argc, char * const argv[])
 {
        while (1) {
-               int key;
-               char *endp;
+               int key, error = 0;
 
                key = getopt_long(argc, argv, "s:S:n:N:h?V", long_options, NULL);
                if (key == -1)
@@ -122,14 +121,14 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 'S':
-                       args.lebs = strtoull(optarg, &endp, 0);
-                       if (endp == optarg || args.lebs <= 0 || *endp != '\0')
+                       args.lebs = simple_strtoull(optarg, &error);
+                       if (error || args.lebs <= 0)
                                return errmsg("bad LEB count: \"%s\"", optarg);
                        break;
 
                case 'n':
-                       args.vol_id = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.vol_id < 0) {
+                       args.vol_id = simple_strtoul(optarg, &error);
+                       if (error || args.vol_id < 0) {
                                errmsg("bad volume ID: " "\"%s\"", optarg);
                                return -1;
                        }
index 4bf41230c07cf569d1e0ce41ac0b16f396ff998f..62f140b992c443de6aeb7ffb05a665791a1a10b7 100644 (file)
@@ -78,8 +78,7 @@ static const struct option long_options[] = {
 static int parse_opt(int argc, char * const argv[])
 {
        while (1) {
-               int key;
-               char *endp;
+               int key, error = 0;
 
                key = getopt_long(argc, argv, "ts:h?V", long_options, NULL);
                if (key == -1)
@@ -91,8 +90,8 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 's':
-                       args.size = strtoul(optarg, &endp, 0);
-                       if (*endp != '\0' || endp == optarg || args.size < 0)
+                       args.size = simple_strtoul(optarg, &error);
+                       if (error || args.size < 0)
                                return errmsg("bad size: " "\"%s\"", optarg);
                        break;