Patchwork [U-Boot,1/2] vsprintf: add ustrtoll function

login
register
mail settings
Submitter Piotr Wilczek
Date Jan. 28, 2013, 8:59 a.m.
Message ID <1359363565-19313-2-git-send-email-p.wilczek@samsung.com>
Download mbox | patch
Permalink /patch/216124/
State Accepted
Delegated to: Tom Rini
Headers show

Comments

Piotr Wilczek - Jan. 28, 2013, 8:59 a.m.
Add 'ustrtoull' function to convert size from string (ex: 1GiB)
to unsigned long long type

Signed-off-by: Piotr Wilczek <p.wilczek@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
 include/exports.h |    1 +
 lib/vsprintf.c    |   23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)
Tom Rini - Feb. 20, 2013, 3:01 p.m.
On Sun, Jan 27, 2013 at 10:59:24PM -0000, Piotr Wilczek wrote:

> Add 'ustrtoull' function to convert size from string (ex: 1GiB)
> to unsigned long long type
> 
> Signed-off-by: Piotr Wilczek <p.wilczek@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>

For the series, applied to u-boot/master, thanks!

Patch

diff --git a/include/exports.h b/include/exports.h
index 6cf31aa..41d5085 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 3c432f8..533a96b 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -126,6 +126,29 @@  unsigned long ustrtoul(const char *cp, char **endp, unsigned int base)
 	return result;
 }
 
+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)
 {