diff options
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 53 |
1 files changed, 52 insertions, 1 deletions
@@ -289,7 +289,7 @@ const char *modeString(int mode) #endif -#ifdef BB_TAR +#if defined BB_TAR /* * Return the standard ls-like time string from a time_t * This is static and so is overwritten on each call. @@ -340,8 +340,10 @@ int fullWrite(int fd, const char *buf, int len) return total; } +#endif +#if defined BB_TAR || defined BB_TAIL /* * Read all of the supplied buffer from a file. * This does multiple reads as necessary. @@ -1018,6 +1020,55 @@ extern void whine_if_fstab_is_missing() #endif +#if defined BB_DD || defined BB_TAIL +/* + * Read a number with a possible multiplier. + * Returns -1 if the number format is illegal. + */ +extern long getNum (const char *cp) +{ + long value; + + if (!isDecimal (*cp)) + return -1; + + value = 0; + + while (isDecimal (*cp)) + value = value * 10 + *cp++ - '0'; + + switch (*cp++) { + case 'm': + value *= 1048576; + break; + + case 'k': + value *= 1024; + break; + + case 'b': + value *= 512; + break; + + case 'w': + value *= 2; + break; + + case '\0': + return value; + + default: + return -1; + } + + if (*cp) + return -1; + + return value; +} +#endif + + /* END CODE */ |