summaryrefslogtreecommitdiff
path: root/lib_generic
diff options
context:
space:
mode:
authorwdenk <wdenk>2004-03-13 23:29:43 +0000
committerwdenk <wdenk>2004-03-13 23:29:43 +0000
commitc40b29568232761e33400e58be86b15a167d3422 (patch)
treec306e01e8cf535467fb448499304020d251a763a /lib_generic
parent6629d2f22b4af180dc41defe2396bafcd8fe4093 (diff)
downloadu-boot-imx-c40b29568232761e33400e58be86b15a167d3422.zip
u-boot-imx-c40b29568232761e33400e58be86b15a167d3422.tar.gz
u-boot-imx-c40b29568232761e33400e58be86b15a167d3422.tar.bz2
* Patch by Rune Torgersen, 27 Feb 2004:
- Added LBA48 support (CONFIG_LBA48 & CFG_64BIT_LBA) - Added support for 64bit printing in vsprintf (CFG_64BIT_VSPRINTF) - Added support for 64bit strtoul (CFG_64BIT_STRTOUL) * Patch by Masami Komiya, 27 Feb 2004: Fix rarpboot: add autoload by NFS * Patch by Dan Eisenhut, 26 Feb 2004: fix flash_write return value in saveenv * Patch by Stephan Linz, 11 Dec 2003 expand config.mk to avoid trigraph warnings on NIOS * Rename "BMS2003" board into "HMI10"
Diffstat (limited to 'lib_generic')
-rw-r--r--lib_generic/vsprintf.c61
1 files changed, 52 insertions, 9 deletions
diff --git a/lib_generic/vsprintf.c b/lib_generic/vsprintf.c
index 6b04453..3fefd61 100644
--- a/lib_generic/vsprintf.c
+++ b/lib_generic/vsprintf.c
@@ -55,6 +55,36 @@ long simple_strtol(const char *cp,char **endp,unsigned int base)
return simple_strtoul(cp,endp,base);
}
+#if CFG_64BIT_STRTOUL
+unsigned long long simple_strtoull (const char *cp, char **endp, unsigned int base)
+{
+ unsigned long long result = 0, value;
+
+ if (*cp == '0') {
+ cp++;
+ if ((*cp == 'x') && isxdigit (cp[1])) {
+ base = 16;
+ cp++;
+ }
+ if (!base) {
+ base = 8;
+ }
+ }
+ if (!base) {
+ base = 10;
+ }
+ while (isxdigit (*cp) && (value = isdigit (*cp)
+ ? *cp - '0'
+ : (islower (*cp) ? toupper (*cp) : *cp) - 'A' + 10) < base) {
+ result = result * base + value;
+ cp++;
+ }
+ if (endp)
+ *endp = (char *) cp;
+ return result;
+}
+#endif /* CFG_64BIT_STRTOUL */
+
/* we use this so that we can do without the ctype library */
#define is_digit(c) ((c) >= '0' && (c) <= '9')
@@ -76,13 +106,17 @@ static int skip_atoi(const char **s)
#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
#define do_div(n,base) ({ \
-int __res; \
-__res = ((unsigned long) n) % (unsigned) base; \
-n = ((unsigned long) n) / (unsigned) base; \
-__res; })
-
-static char * number(char * str, long num, int base, int size, int precision
- ,int type)
+ int __res; \
+ __res = ((unsigned long) n) % (unsigned) base; \
+ n = ((unsigned long) n) / (unsigned) base; \
+ __res; \
+})
+
+#if CFG_64BIT_VSPRINTF
+static char * number(char * str, long long num, int base, int size, int precision ,int type)
+#else
+static char * number(char * str, long num, int base, int size, int precision ,int type)
+#endif
{
char c,sign,tmp[66];
const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
@@ -154,7 +188,11 @@ int sprintf(char * buf, const char *fmt, ...);
int vsprintf(char *buf, const char *fmt, va_list args)
{
int len;
+#if CFG_64BIT_VSPRINTF
+ unsigned long long num;
+#else
unsigned long num;
+#endif
int i, base;
char * str;
const char *s;
@@ -164,7 +202,7 @@ int vsprintf(char *buf, const char *fmt, va_list args)
int field_width; /* width of output field */
int precision; /* min. # of digits for integers; max
number of chars for from string */
- int qualifier; /* 'h', 'l', or 'L' for integer fields */
+ int qualifier; /* 'h', 'l', or 'q' for integer fields */
for (str=buf ; *fmt ; ++fmt) {
if (*fmt != '%') {
@@ -215,7 +253,7 @@ int vsprintf(char *buf, const char *fmt, va_list args)
/* get the conversion qualifier */
qualifier = -1;
- if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
+ if (*fmt == 'h' || *fmt == 'l' || *fmt == 'q') {
qualifier = *fmt;
++fmt;
}
@@ -299,6 +337,11 @@ int vsprintf(char *buf, const char *fmt, va_list args)
--fmt;
continue;
}
+#if CFG_64BIT_VSPRINTF
+ if (qualifier == 'q') /* "quad" for 64 bit variables */
+ num = va_arg(args, unsigned long long);
+ else
+#endif
if (qualifier == 'l')
num = va_arg(args, unsigned long);
else if (qualifier == 'h') {