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
This commit is contained in:
gary.li.wenchao.4 2010-03-14 12:47:41 +00:00
parent e02d3fe86e
commit 6740422c84
1 changed files with 23 additions and 17 deletions

View File

@ -21,17 +21,17 @@
/* there is no strcpy and strcmp implementation in RT-Thread */ /* there is no strcpy and strcmp implementation in RT-Thread */
char *strcpy(char *dest, const char *src) 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) 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) 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) 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') { if (*cp == '0') {
base = 8; base = 8;
cp++; cp++;
if ((*cp == 'x') && isxdigit(cp[1])) { if ((toupper(*cp) == 'X') && isxdigit(cp[1])) {
cp++; cp++;
base = 16; base = 16;
} }
} }
} else if (base == 16) {
if (cp[0] == '0' && toupper(cp[1]) == 'X')
cp += 2;
} }
while (isxdigit(*cp) && while (isxdigit(*cp) &&
(value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) { (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 simple_strtoull(const char *cp,char **endp,unsigned int base)
{ {
unsigned long long result = 0,value; unsigned long long result = 0, value;
if (!base) { if (*cp == '0') {
base = 10; cp++;
if (*cp == '0') { if ((toupper(*cp) == 'X') && isxdigit (cp[1])) {
base = 8; base = 16;
cp++; cp++;
if ((*cp == 'x') && isxdigit(cp[1])) { }
cp++; if (!base) {
base = 16; base = 8;
}
} }
} }
while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) if (!base) {
? toupper(*cp) : *cp)-'A'+10) < base) { base = 10;
result = result*base + value; }
while (isxdigit (*cp) && (value = isdigit (*cp)
? *cp - '0'
: (islower (*cp) ? toupper (*cp) : *cp) - 'A' + 10) < base) {
result = result * base + value;
cp++; cp++;
} }
if (endp) if (endp)
*endp = (char *)cp; *endp = (char *) cp;
return result; return result;
} }