From: Piotr Wilczek Date: Sun, 27 Jan 2013 22:59:24 +0000 (+0000) Subject: vsprintf: add ustrtoll function X-Git-Tag: submit/tizen/20160318.071304~340 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=42364e985f05d331aff384e03bff8514ff797bbb;p=profile%2Fcommon%2Fplatform%2Fkernel%2Fu-boot-artik.git vsprintf: add ustrtoll function Add 'ustrtoull' function to convert size from string (ex: 1GiB) to unsigned long long type Signed-off-by: Piotr Wilczek Signed-off-by: Kyungmin Park Conflicts: lib/vsprintf.c --- diff --git a/include/exports.h b/include/exports.h index 6cf31aa5e..41d5085e1 100644 --- a/include/exports.h +++ b/include/exports.h @@ -24,6 +24,7 @@ int setenv (const char *varname, const char *varvalue); long simple_strtol(const char *cp,char **endp,unsigned int base); int strcmp(const char * cs,const char * ct); unsigned long ustrtoul(const char *cp, char **endp, unsigned int base); +unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base); #if defined(CONFIG_CMD_I2C) int i2c_write (uchar, uint, int , uchar* , int); int i2c_read (uchar, uint, int , uchar* , int); diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 27cb83612..d8b14f07f 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -121,7 +121,31 @@ unsigned long ustrtoul(const char *cp, char **endp, unsigned int base) return result; } -unsigned long long simple_strtoull (const char *cp, char **endp, unsigned int base) +unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base) +{ + unsigned long long result = simple_strtoull(cp, endp, base); + switch (**endp) { + case 'G': + result *= 1024; + /* fall through */ + case 'M': + result *= 1024; + /* fall through */ + case 'K': + case 'k': + result *= 1024; + if ((*endp)[1] == 'i') { + if ((*endp)[2] == 'B') + (*endp) += 3; + else + (*endp) += 2; + } + } + return result; +} + +unsigned long long simple_strtoull(const char *cp, char **endp, + unsigned int base) { unsigned long long result = 0, value;