aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-02-16 21:08:22 -0500
committerRob Landley <rob@landley.net>2007-02-16 21:08:22 -0500
commitf5757161aff8caeec8e70b9709ccdce96e41dd14 (patch)
treeb2ecd70a091018aa2999d93d64875390688c8634 /lib/lib.c
parentfb6c09e63653b619f6645617d66ba605077d1d42 (diff)
downloadtoybox-f5757161aff8caeec8e70b9709ccdce96e41dd14.tar.gz
Add atolx() which understands extensions for kilobytes and megabytes and such.
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index f1d1ce1f..6c8abb03 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -402,6 +402,18 @@ char *itoa(int n)
return itoa_buf;
}
+// atol() with the kilo/mega/giga/tera/peta/exa extensions.
+// (zetta and yotta don't fit in 64 bits.)
+long atolx(char *c)
+{
+ char *suffixes="kmgtpe", *end;
+ long val = strtol(c, &c, 0);
+
+ end = strchr(suffixes, tolower(*c));
+ if (end) val *= 1024<<((end-suffixes)*10);
+ return val;
+}
+
// Return how long the file at fd is, if there's any way to determine it.
off_t fdlength(int fd)
{