From: Johannes Schindelin Date: Thu, 12 Jul 2007 13:07:39 GMT Subject: Re: [PATCH 3/6] Add functions for parsing integers with size suffixes Message-ID: In-Reply-To: <1184244952173-git-send-email-bdowning@lavos.net> Hi, On Thu, 12 Jul 2007, Brian Downing wrote: > Split out the nnn{k,m,g} parsing code from git_config_int into > git_parse_long, so command-line parameters can enjoy the same > functionality. Also add get_parse_ulong for unsigned values. Nice! > + if (!*end) > + *ret = val; > + else if (!strcasecmp(end, "k")) > + *ret = val * 1024; > + else if (!strcasecmp(end, "m")) > + *ret = val * 1024 * 1024; > + else if (!strcasecmp(end, "g")) > + *ret = val * 1024 * 1024 * 1024; > + else > + return 0; This could be an own static function, like this: unsigned long get_unit_factor(const char *end) { if (!*end) return 1; if (!strcasecmp(end, "k")) return 1024; ... error("Unknown unit: %s", end); return 1; } to avoid duplicated code. Ciao, Dscho