diff --git a/libc/minilibc/string.c b/libc/minilibc/string.c index 3eac377c7..a306016d2 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; }