summaryrefslogtreecommitdiff
path: root/e2fsprogs/old_e2fsprogs/e2p/parse_num.c
diff options
context:
space:
mode:
authorDenis Vlasenko2006-12-26 01:30:59 +0000
committerDenis Vlasenko2006-12-26 01:30:59 +0000
commitc4f623ef2a7980a63de7c9f1d539a656b83f10e7 (patch)
treea294e28b0112052cb9d58b403554b3390e76f50c /e2fsprogs/old_e2fsprogs/e2p/parse_num.c
parent64c54025842f205ad722675105b88044a5b6845a (diff)
downloadbusybox-c4f623ef2a7980a63de7c9f1d539a656b83f10e7.zip
busybox-c4f623ef2a7980a63de7c9f1d539a656b83f10e7.tar.gz
put small subset of e2fsprogs back in the tree:
lsattr, chattr, fsck. Old e2fsprogs tree is in e2fsprogs/old_e2fsprogs/*.
Diffstat (limited to 'e2fsprogs/old_e2fsprogs/e2p/parse_num.c')
-rw-r--r--e2fsprogs/old_e2fsprogs/e2p/parse_num.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/e2fsprogs/old_e2fsprogs/e2p/parse_num.c b/e2fsprogs/old_e2fsprogs/e2p/parse_num.c
new file mode 100644
index 0000000..6db076f
--- /dev/null
+++ b/e2fsprogs/old_e2fsprogs/e2p/parse_num.c
@@ -0,0 +1,65 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * parse_num.c - Parse the number of blocks
+ *
+ * Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu>
+ *
+ * This file can be redistributed under the terms of the GNU Library General
+ * Public License
+ */
+
+#include "e2p.h"
+
+#include <stdlib.h>
+
+unsigned long parse_num_blocks(const char *arg, int log_block_size)
+{
+ char *p;
+ unsigned long long num;
+
+ num = strtoull(arg, &p, 0);
+
+ if (p[0] && p[1])
+ return 0;
+
+ switch (*p) { /* Using fall-through logic */
+ case 'T': case 't':
+ num <<= 10;
+ case 'G': case 'g':
+ num <<= 10;
+ case 'M': case 'm':
+ num <<= 10;
+ case 'K': case 'k':
+ num >>= log_block_size;
+ break;
+ case 's':
+ num >>= 1;
+ break;
+ case '\0':
+ break;
+ default:
+ return 0;
+ }
+ return num;
+}
+
+#ifdef DEBUG
+#include <unistd.h>
+#include <stdio.h>
+
+main(int argc, char **argv)
+{
+ unsigned long num;
+ int log_block_size = 0;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s arg\n", argv[0]);
+ exit(1);
+ }
+
+ num = parse_num_blocks(argv[1], log_block_size);
+
+ printf("Parsed number: %lu\n", num);
+ exit(0);
+}
+#endif