Btrfs-progs: switch to arg_strtou64() part1
authorWang Shilong <wangsl.fnst@cn.fujitsu.com>
Thu, 20 Feb 2014 01:30:50 +0000 (09:30 +0800)
committerChris Mason <clm@fb.com>
Fri, 21 Mar 2014 13:23:19 +0000 (06:23 -0700)
switch to arg_strtou64 plus some cleanups to remove unnecessary
codes.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
btrfs-find-root.c
btrfs-list.c
cmds-restore.c

index 0ba4c57..db01923 100644 (file)
@@ -289,30 +289,13 @@ int main(int argc, char **argv)
                switch(opt) {
                        errno = 0;
                        case 'o':
-                               search_objectid = (u64)strtoll(optarg, NULL,
-                                                              10);
-                               if (errno) {
-                                       fprintf(stderr, "Error parsing "
-                                               "objectid\n");
-                                       exit(1);
-                               }
+                               search_objectid = arg_strtou64(optarg);
                                break;
                        case 'g':
-                               search_generation = (u64)strtoll(optarg, NULL,
-                                                              10);
-                               if (errno) {
-                                       fprintf(stderr, "Error parsing "
-                                               "generation\n");
-                                       exit(1);
-                               }
+                               search_generation = arg_strtou64(optarg);
                                break;
                        case 'l':
-                               search_level = strtol(optarg, NULL, 10);
-                               if (errno) {
-                                       fprintf(stderr, "Error parsing "
-                                               "level\n");
-                                       exit(1);
-                               }
+                               search_level = arg_strtou64(optarg);
                                break;
                        default:
                                usage();
index 9effb27..912b27c 100644 (file)
@@ -1854,32 +1854,24 @@ int btrfs_list_parse_filter_string(char *opt_arg,
 {
 
        u64 arg;
-       char *ptr_parse_end = NULL;
-       char *ptr_opt_arg_end = opt_arg + strlen(opt_arg);
 
        switch (*(opt_arg++)) {
        case '+':
-               arg = (u64)strtol(opt_arg, &ptr_parse_end, 10);
+               arg = arg_strtou64(opt_arg);
                type += 2;
-               if (ptr_parse_end != ptr_opt_arg_end)
-                       return -1;
 
                btrfs_list_setup_filter(filters, type, arg);
                break;
        case '-':
-               arg = (u64)strtoll(opt_arg, &ptr_parse_end, 10);
+               arg = arg_strtou64(opt_arg);
                type += 1;
-               if (ptr_parse_end != ptr_opt_arg_end)
-                       return -1;
 
                btrfs_list_setup_filter(filters, type, arg);
                break;
        default:
                opt_arg--;
-               arg = (u64)strtoll(opt_arg, &ptr_parse_end, 10);
+               arg = arg_strtou64(opt_arg);
 
-               if (ptr_parse_end != ptr_opt_arg_end)
-                       return -1;
                btrfs_list_setup_filter(filters, type, arg);
                break;
        }
index fd533ce..6659c75 100644 (file)
@@ -1160,26 +1160,14 @@ int cmd_restore(int argc, char **argv)
                                overwrite = 1;
                                break;
                        case 't':
-                               errno = 0;
-                               tree_location = (u64)strtoll(optarg, NULL, 10);
-                               if (errno != 0) {
-                                       fprintf(stderr, "Tree location not valid\n");
-                                       exit(1);
-                               }
+                               tree_location = arg_strtou64(optarg);
                                break;
                        case 'f':
-                               errno = 0;
-                               fs_location = (u64)strtoll(optarg, NULL, 10);
-                               if (errno != 0) {
-                                       fprintf(stderr, "Fs location not valid\n");
-                                       exit(1);
-                               }
+                               fs_location = arg_strtou64(optarg);
                                break;
                        case 'u':
-                               errno = 0;
-                               super_mirror = (int)strtol(optarg, NULL, 10);
-                               if (errno != 0 ||
-                                   super_mirror >= BTRFS_SUPER_MIRROR_MAX) {
+                               super_mirror = arg_strtou64(optarg);
+                               if (super_mirror >= BTRFS_SUPER_MIRROR_MAX) {
                                        fprintf(stderr, "Super mirror not "
                                                "valid\n");
                                        exit(1);
@@ -1189,12 +1177,7 @@ int cmd_restore(int argc, char **argv)
                                find_dir = 1;
                                break;
                        case 'r':
-                               errno = 0;
-                               root_objectid = (u64)strtoll(optarg, NULL, 10);
-                               if (errno != 0) {
-                                       fprintf(stderr, "Root objectid not valid\n");
-                                       exit(1);
-                               }
+                               root_objectid = arg_strtou64(optarg);
                                break;
                        case 'l':
                                list_roots = 1;