Whamcloud - gitweb
git://git.whamcloud.com
/
tools
/
e2fsprogs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lib/e2p: fix a -Wunused-variable warning in getflags()
[tools/e2fsprogs.git]
/
lib
/
e2p
/
parse_num.c
diff --git
a/lib/e2p/parse_num.c
b/lib/e2p/parse_num.c
index
5b53215
..
e8d6283
100644
(file)
--- a/
lib/e2p/parse_num.c
+++ b/
lib/e2p/parse_num.c
@@
-3,10
+3,13
@@
*
* Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu>
*
*
* 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
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
+ * %End-Header%
*/
*/
+#include "config.h"
#include "e2p.h"
#include <stdlib.h>
#include "e2p.h"
#include <stdlib.h>
@@
-24,15
+27,24
@@
unsigned long long parse_num_blocks2(const char *arg, int log_block_size)
switch (*p) { /* Using fall-through logic */
case 'T': case 't':
num <<= 10;
switch (*p) { /* Using fall-through logic */
case 'T': case 't':
num <<= 10;
+ /* fallthrough */
case 'G': case 'g':
num <<= 10;
case 'G': case 'g':
num <<= 10;
+ /* fallthrough */
case 'M': case 'm':
num <<= 10;
case 'M': case 'm':
num <<= 10;
+ /* fallthrough */
case 'K': case 'k':
case 'K': case 'k':
- num >>= log_block_size;
+ if (log_block_size < 0)
+ num <<= 10;
+ else
+ num >>= log_block_size;
break;
case 's':
break;
case 's':
- num >>= (1+log_block_size);
+ if (log_block_size < 0)
+ num <<= 9;
+ else
+ num >>= (1+log_block_size);
break;
case '\0':
break;
break;
case '\0':
break;
@@
-56,11
+68,21
@@
main(int argc, char **argv)
unsigned long num;
int log_block_size = 0;
unsigned long num;
int log_block_size = 0;
- if (argc != 2) {
- fprintf(stderr, "Usage: %s arg\n", argv[0]);
+ if (argc != 2
&& argc != 3
) {
+ fprintf(stderr, "Usage: %s arg
[log_block_size]
\n", argv[0]);
exit(1);
}
exit(1);
}
+ if (argc == 3) {
+ char *p;
+
+ log_block_size = strtol(argv[2], &p, 0);
+ if (*p) {
+ fprintf(stderr, "Bad log_block_size: %s\n", argv[2]);
+ exit(1);
+ }
+ }
+
num = parse_num_blocks(argv[1], log_block_size);
printf("Parsed number: %lu\n", num);
num = parse_num_blocks(argv[1], log_block_size);
printf("Parsed number: %lu\n", num);