X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=misc.c;h=59e91f2f6033ddfc65d9c90206114b53ccb43e20;hb=ac61490a5b9f40a3655d363d5a1014112aae7222;hp=474bf0249dd3d235a730a0a56c4a70ecdf6b5b86;hpb=7ecf13564a8d716000ce78146d1aaf4422432a4f;p=PuTTY.git diff --git a/misc.c b/misc.c index 474bf024..59e91f2f 100644 --- a/misc.c +++ b/misc.c @@ -9,6 +9,39 @@ #include #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. */