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 */
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;
}