]> www.infradead.org Git - mtd-utils.git/commitdiff
nandtest: support hex/dec/oct for --offset and --length
authorBrian Norris <computersforpeace@gmail.com>
Fri, 30 Oct 2015 00:12:01 +0000 (17:12 -0700)
committerBrian Norris <computersforpeace@gmail.com>
Wed, 11 Nov 2015 22:05:07 +0000 (14:05 -0800)
These two options are handled inconsistently, which caused an
unnecessary amount of head scratching. Let's just use the simple helpers
too, so we get the error handling right.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
nandtest.c

index 08053876506aebcc9e3b073c936e3525acca8594..2ef7cc824d59a8689cea759155e73eb3413e07e8 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <asm/types.h>
 #include "mtd/mtd-user.h"
+#include "common.h"
 
 void usage(int status)
 {
@@ -154,6 +155,7 @@ int main(int argc, char **argv)
        int keep_contents = 0;
        uint32_t offset = 0;
        uint32_t length = -1;
+       int error = 0;
 
        seed = time(NULL);
 
@@ -205,17 +207,19 @@ int main(int argc, char **argv)
                        break;
 
                case 'o':
-                       offset = atol(optarg);
+                       offset = simple_strtoul(optarg, &error);
                        break;
 
                case 'l':
-                       length = strtol(optarg, NULL, 0);
+                       length = simple_strtoul(optarg, &error);
                        break;
 
                }
        }
        if (argc - optind != 1)
                usage(1);
+       if (error)
+               errmsg_die("Try --help for more information");
 
        fd = open(argv[optind], O_RDWR);
        if (fd < 0) {