aboutsummaryrefslogtreecommitdiffstats
path: root/src/misc.c
diff options
context:
space:
mode:
authorMartin Pärtel <martin.partel@gmail.com>2014-06-30 22:50:14 +0100
committerMartin Pärtel <martin.partel@gmail.com>2014-06-30 22:50:14 +0100
commit9bf3ec8cd48c835e02ff96cd97d1581b2f9ba5b3 (patch)
tree05e8bfc74fdb13c1724991e3ee57308c7cf4a9a7 /src/misc.c
parent3f7daee57d1e57ef522447fd601805971bb358c8 (diff)
downloadbindfs-9bf3ec8cd48c835e02ff96cd97d1581b2f9ba5b3.tar.gz
Implemented rate limiter.
Fixes #12.
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/misc.c b/src/misc.c
index 799f555..4442127 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -108,7 +108,7 @@ const char *my_dirname(char *path)
}
}
-void grow_array_impl(void **array, int* capacity, int member_size)
+void grow_array_impl(void **array, int *capacity, int member_size)
{
int new_cap = *capacity;
if (new_cap == 0) {
@@ -121,6 +121,28 @@ void grow_array_impl(void **array, int* capacity, int member_size)
*capacity = new_cap;
}
+int parse_byte_count(const char *str, double *result)
+{
+ char* end;
+ double base = strtod(str, &end);
+ long mul = 1;
+ if (*end == '\0') {
+ mul = 1L;
+ } else if (strcmp(end, "k") == 0) {
+ mul = 1024L;
+ } else if (strcmp(end, "M") == 0) {
+ mul = 1024L * 1024L;
+ } else if (strcmp(end, "G") == 0) {
+ mul = 1024L * 1024L * 1024L;
+ } else if (strcmp(end, "T") == 0) {
+ mul = 1024L * 1024L * 1024L * 1024L;
+ } else {
+ return 0;
+ }
+ *result = base * mul;
+ return 1;
+}
+
void init_arena(struct arena *a, int initial_capacity)
{
a->size = 0;