add atol and isspace to minilibc.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2218 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
qiuyiuestc@gmail.com 2012-07-12 22:42:06 +00:00
parent ae3c1800d4
commit 70cee4b82e
4 changed files with 36 additions and 1 deletions

View File

@ -31,7 +31,23 @@ int isalpha(int ch)
int isdigit (int ch)
{
return (unsigned int)(ch - '0') < 10u;
return (unsigned int)(ch - '0') < 10u;
}
int isspace(int ch)
{
switch(ch)
{
case ' ':
case '\n':
case '\f':
case '\r':
case '\t':
case '\v':
return 1;
default:
return 0;
}
}
#endif

View File

@ -17,5 +17,6 @@
int isprint(int c) __attribute__ ((__const__));
int isalpha (int c) __attribute__ ((__const__));
int isdigit (int ch) __attribute__ ((__const__));
int isspace(int ch) __attribute__ ((__const__));
#endif

View File

@ -37,6 +37,23 @@ int atoi(const char* s)
return sign==-1?-v:v;
}
long int atol(const char* s)
{
long int v=0;
int sign=0;
while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) ++s;
switch (*s)
{
case '-': sign=-1;
case '+': ++s;
}
while ((unsigned int) (*s - '0') < 10u)
{
v=v*10+*s-'0'; ++s;
}
return sign?-v:v;
}
void *malloc(size_t size)
{
return rt_malloc(size);

View File

@ -19,6 +19,7 @@
#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
int atoi(const char *nptr);
long int atol(const char *nptr);
int rand(void);
int rand_r(unsigned int *seed);