X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/786ba75e61df3c1c4a723117652c62259358e9e2..d57f70afa40c24426e5f936c86f7640801d43f7a:/misc.c 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. */