2 * parse_num.c - Parse the number of blocks
4 * Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu>
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
17 unsigned long long parse_num_blocks2(const char *arg, int log_block_size)
20 unsigned long long num;
22 num = strtoull(arg, &p, 0);
27 switch (*p) { /* Using fall-through logic */
38 if (log_block_size < 0)
41 num >>= log_block_size;
44 if (log_block_size < 0)
47 num >>= (1+log_block_size);
57 unsigned long parse_num_blocks(const char *arg, int log_block_size)
59 return parse_num_blocks2(arg, log_block_size);
66 main(int argc, char **argv)
69 int log_block_size = 0;
71 if (argc != 2 && argc != 3) {
72 fprintf(stderr, "Usage: %s arg [log_block_size]\n", argv[0]);
79 log_block_size = strtol(argv[2], &p, 0);
81 fprintf(stderr, "Bad log_block_size: %s\n", argv[2]);
86 num = parse_num_blocks(argv[1], log_block_size);
88 printf("Parsed number: %lu\n", num);