summaryrefslogtreecommitdiffstats
path: root/sys-utils/fallocate.c
diff options
context:
space:
mode:
authorKarel Zak2010-03-30 14:28:13 +0200
committerKarel Zak2010-03-30 14:45:37 +0200
commit3b6b039ae899945895839b29359313cf4ef561c9 (patch)
tree1bada8eaa2b775195ab984cc69c7e36f72b13859 /sys-utils/fallocate.c
parentmkswap: more robust strtoull() usage (diff)
downloadkernel-qcow2-util-linux-3b6b039ae899945895839b29359313cf4ef561c9.tar.gz
kernel-qcow2-util-linux-3b6b039ae899945895839b29359313cf4ef561c9.tar.xz
kernel-qcow2-util-linux-3b6b039ae899945895839b29359313cf4ef561c9.zip
fallocate: support suffixes for --offset and --lenght
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/fallocate.c')
-rw-r--r--sys-utils/fallocate.c40
1 files changed, 4 insertions, 36 deletions
diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c
index be715777b..e41643a2f 100644
--- a/sys-utils/fallocate.c
+++ b/sys-utils/fallocate.c
@@ -40,6 +40,7 @@
#include <linux/falloc.h> /* for FALLOC_FL_* flags */
#include "nls.h"
+#include "strtosize.h"
static void __attribute__((__noreturn__)) usage(FILE *out)
@@ -58,47 +59,14 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-#define EXABYTES(x) ((x) << 60)
-#define PETABYTES(x) ((x) << 50)
-#define TERABYTES(x) ((x) << 40)
-#define GIGABYTES(x) ((x) << 30)
-#define MEGABYTES(x) ((x) << 20)
-#define KILOBYTES(x) ((x) << 10)
-
static loff_t cvtnum(char *s)
{
- loff_t i;
- char *sp;
-
- errno = 0;
- i = strtoll(s, &sp, 0);
+ uintmax_t x;
- if ((errno == ERANGE && (i == LLONG_MAX || i == LLONG_MIN)) ||
- (errno != 0 && i == 0))
- return -1LL;
- if (i == 0 && sp == s)
+ if (strtosize(s, &x))
return -1LL;
- if (*sp == '\0')
- return i;
- if (sp[1] != '\0')
- return -1LL;
-
- switch (tolower(*sp)) {
- case 'k':
- return KILOBYTES(i);
- case 'm':
- return MEGABYTES(i);
- case 'g':
- return GIGABYTES(i);
- case 't':
- return TERABYTES(i);
- case 'p':
- return PETABYTES(i);
- case 'e':
- return EXABYTES(i);
- }
- return -1LL;
+ return x;
}
int main(int argc, char **argv)