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.
16 unsigned long long parse_num_blocks2(const char *arg, int log_block_size)
19 unsigned long long num;
21 num = strtoull(arg, &p, 0);
26 switch (*p) { /* Using fall-through logic */
34 num >>= log_block_size;
37 num >>= (1+log_block_size);
47 unsigned long parse_num_blocks(const char *arg, int log_block_size)
49 return parse_num_blocks2(arg, log_block_size);
56 main(int argc, char **argv)
59 int log_block_size = 0;
62 fprintf(stderr, "Usage: %s arg\n", argv[0]);
66 num = parse_num_blocks(argv[1], log_block_size);
68 printf("Parsed number: %lu\n", num);