]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
disk-utils: cleanup strtoxx_or_err()
authorKarel Zak <kzak@redhat.com>
Tue, 15 May 2012 15:43:32 +0000 (17:43 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 15 May 2012 15:43:32 +0000 (17:43 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/mkfs.bfs.c
disk-utils/mkfs.cramfs.c
disk-utils/mkswap.c

index b37a947290974f7a5d06cce3aeb7f7c2a130be7b..c93067e2026a6cbd2783c50c69ee9894193afa02 100644 (file)
@@ -185,7 +185,7 @@ int main(int argc, char **argv)
 
        if (optind == argc - 1)
                user_specified_total_blocks =
-                       strtoll_or_err(argv[optind], _("invalid block-count"));
+                       strtou64_or_err(argv[optind], _("invalid block-count"));
        else if (optind != argc)
                usage(stderr);
 
index 8e38a8c89ac24abcea858052fc271f80d95f2733..919f1efbf783041857ff2ea79a60ebb2696e4837 100644 (file)
@@ -66,7 +66,7 @@ static int cramfs_is_big_endian = 0; /* target is big endian */
  * Note that kernels up to at least 2.3.39 don't support cramfs holes,
  * which is why this is turned off by default.
  */
-static int opt_edition = 0;
+static unsigned int opt_edition = 0;
 static int opt_errors = 0;
 static int opt_holes = 0;
 static int opt_pad = 0;
@@ -727,20 +727,13 @@ int main(int argc, char **argv)
                case 'h':
                        usage(MKFS_EX_OK);
                case 'b':
-               {
-                       long long tmp = strtoll_or_err(optarg,
-                                       _("failed to parse blocksize argument"));
-
-                       if (tmp <= 0 || UINT_MAX < tmp)
-                               errx(MKFS_EX_USAGE, _("invalid block size"));
-                       blksize = tmp;
+                       blksize = strtou32_or_err(optarg, _("invalid blocksize argument"));
                        break;
-               }
                case 'E':
                        opt_errors = 1;
                        break;
                case 'e':
-                       opt_edition = strtoll_or_err(optarg, _("edition number argument failed"));
+                       opt_edition = strtou32_or_err(optarg, _("edition number argument failed"));
                        break;
                case 'N':
                        if (strcmp(optarg, "big") == 0)
index db465b7c2dd33cd6136e4126464d626b00c7378c..ca49d0e34f407925eb59d61675a9e1af46488048 100644 (file)
@@ -145,21 +145,21 @@ is_sparc64(void)
  * What to do? Let us allow the user to specify the pagesize explicitly.
  *
  */
-static long user_pagesize;
-static int pagesize;
+static unsigned int user_pagesize;
+static unsigned int pagesize;
 static unsigned long *signature_page = NULL;
 
 static void
 init_signature_page(void)
 {
 
-       int kernel_pagesize = pagesize = getpagesize();
+       unsigned int kernel_pagesize = pagesize = getpagesize();
 
        if (user_pagesize) {
-               if ((user_pagesize & (user_pagesize - 1)) ||
-                   user_pagesize < (long) sizeof(struct swap_header_v1_2) + 10)
+               if (!is_power_of_2(user_pagesize) ||
+                   user_pagesize < sizeof(struct swap_header_v1_2) + 10)
                        errx(EXIT_FAILURE,
-                               _("Bad user-specified page size %lu"),
+                               _("Bad user-specified page size %u"),
                                user_pagesize);
                pagesize = user_pagesize;
        }
@@ -452,7 +452,7 @@ main(int argc, char **argv) {
        unsigned long long sz;
        off_t offset;
        int force = 0;
-       long version = 1;
+       int version = 1;
        char *block_count = 0;
        char *opt_label = NULL;
        unsigned char *uuid = NULL;
@@ -486,13 +486,13 @@ main(int argc, char **argv) {
                        force=1;
                        break;
                case 'p':
-                       user_pagesize = strtol_or_err(optarg, _("parse page size failed"));
+                       user_pagesize = strtou32_or_err(optarg, _("parse page size failed"));
                        break;
                case 'L':
                        opt_label = optarg;
                        break;
                case 'v':
-                       version = strtol_or_err(optarg, _("parse version number failed"));
+                       version = strtos32_or_err(optarg, _("parse version number failed"));
                        break;
                case 'U':
 #ifdef HAVE_LIBUUID
@@ -503,8 +503,7 @@ main(int argc, char **argv) {
 #endif
                        break;
                case 'V':
-                       printf(_("%s from %s\n"), program_invocation_short_name,
-                                                 PACKAGE_STRING);
+                       printf(UTIL_LINUX_VERSION);
                        exit(EXIT_SUCCESS);
                case 'h':
                        usage(stdout);
@@ -523,8 +522,7 @@ main(int argc, char **argv) {
 
        if (version != 1)
                errx(EXIT_FAILURE,
-                       _("does not support swapspace version %lu."),
-                       version);
+                       _("does not support swapspace version %d."), version);
 
 #ifdef HAVE_LIBUUID
        if(opt_uuid) {
@@ -543,12 +541,8 @@ main(int argc, char **argv) {
        }
        if (block_count) {
                /* this silly user specified the number of blocks explicitly */
-               long long blks;
-
-               blks = strtoll_or_err(block_count, "parse block count failed");
-               if (blks < 0)
-                       usage(stderr);
-
+               uint64_t blks = strtou64_or_err(block_count,
+                                       _("invalid block count argument"));
                PAGES = blks / (pagesize / 1024);
        }
        sz = get_size(device_name);