Basic configurability for client-initiated rekeys.
[sgt/putty] / misc.c
diff --git a/misc.c b/misc.c
index 474bf02..59e91f2 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -9,6 +9,39 @@
 #include <assert.h>
 #include "putty.h"
 
+/*
+ * Parse a string block size specification. This is approximately a
+ * subset of the block size specs supported by GNU fileutils:
+ *  "nk" = n kilobytes
+ *  "nM" = n megabytes
+ *  "nG" = n gigabytes
+ * All numbers are decimal, and suffixes refer to powers of two.
+ * Case-insensitive.
+ */
+unsigned long parse_blocksize(const char *bs)
+{
+    char *suf;
+    unsigned long r = strtoul(bs, &suf, 10);
+    if (*suf != '\0') {
+       while (isspace(*suf)) suf++;
+       switch (*suf) {
+         case 'k': case 'K':
+           r *= 1024ul;
+           break;
+         case 'm': case 'M':
+           r *= 1024ul * 1024ul;
+           break;
+         case 'g': case 'G':
+           r *= 1024ul * 1024ul * 1024ul;
+           break;
+         case '\0':
+         default:
+           break;
+       }
+    }
+    return r;
+}
+
 /* ----------------------------------------------------------------------
  * String handling routines.
  */