diff options
| author | gary.li.wenchao.4 <[email protected]> | 2010-03-14 12:47:41 +0000 |
|---|---|---|
| committer | gary.li.wenchao.4 <[email protected]> | 2010-03-14 12:47:41 +0000 |
| commit | 6740422c8461a49773f8a64bd40e343f900a7ab1 (patch) | |
| tree | 10d029327fa690f2644d5ba97242fd102fa29cb1 /libc | |
| parent | e02d3fe86ec7a80e771ba57416a002d65c8d662a (diff) | |
Fixed implicit errors of simple_strtoul() and simple_strtoull()
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@484 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'libc')
| -rw-r--r-- | libc/minilibc/string.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/libc/minilibc/string.c b/libc/minilibc/string.c index 3eac377c7a..a306016d2e 100644 --- a/libc/minilibc/string.c +++ b/libc/minilibc/string.c @@ -21,17 +21,17 @@ /* there is no strcpy and strcmp implementation in RT-Thread */ char *strcpy(char *dest, const char *src) { - return rt_strncpy(dest, src, rt_strlen(src) + 1); + return (char *)rt_strncpy(dest, src, rt_strlen(src) + 1); } char *strncpy(char *dest, const char *src, rt_ubase_t n) { - return rt_strncpy(dest, src, n); + return (char *)rt_strncpy(dest, src, n); } char *strlcpy(char *dest, const char *src, rt_ubase_t n) { - return rt_strlcpy(dest, src, n); + return (char *)rt_strlcpy(dest, src, n); } int strcmp (const char *s1, const char *s2) @@ -243,11 +243,14 @@ unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) if (*cp == '0') { base = 8; cp++; - if ((*cp == 'x') && isxdigit(cp[1])) { + if ((toupper(*cp) == 'X') && isxdigit(cp[1])) { cp++; base = 16; } } + } else if (base == 16) { + if (cp[0] == '0' && toupper(cp[1]) == 'X') + cp += 2; } while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) { @@ -280,26 +283,29 @@ long simple_strtol(const char *cp,char **endp,unsigned int base) */ unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base) { - unsigned long long result = 0,value; + unsigned long long result = 0, value; - if (!base) { - base = 10; - if (*cp == '0') { - base = 8; + if (*cp == '0') { + cp++; + if ((toupper(*cp) == 'X') && isxdigit (cp[1])) { + base = 16; cp++; - if ((*cp == 'x') && isxdigit(cp[1])) { - cp++; - base = 16; - } + } + if (!base) { + base = 8; } } - while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) - ? toupper(*cp) : *cp)-'A'+10) < base) { - result = result*base + value; + 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; + *endp = (char *) cp; return result; } |
