summaryrefslogtreecommitdiff
path: root/components/libc
diff options
context:
space:
mode:
author[email protected] <[email protected]>2012-07-12 22:42:06 +0000
committer[email protected] <[email protected]>2012-07-12 22:42:06 +0000
commit70cee4b82eb05b0979df7bd999be38ce3b12b76c (patch)
treea8131f3eb6491c4080979034cfdbb96b7a9f5142 /components/libc
parentae3c1800d4e8c2feabd2f09bd164ddb8b0614f7d (diff)
add atol and isspace to minilibc.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2218 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/libc')
-rw-r--r--components/libc/minilibc/ctype.c18
-rw-r--r--components/libc/minilibc/ctype.h1
-rw-r--r--components/libc/minilibc/stdlib.c17
-rw-r--r--components/libc/minilibc/stdlib.h1
4 files changed, 36 insertions, 1 deletions
diff --git a/components/libc/minilibc/ctype.c b/components/libc/minilibc/ctype.c
index 786ff472f8..4fd2dc8fb5 100644
--- a/components/libc/minilibc/ctype.c
+++ b/components/libc/minilibc/ctype.c
@@ -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
diff --git a/components/libc/minilibc/ctype.h b/components/libc/minilibc/ctype.h
index 9a773b69ab..9909b4a0b0 100644
--- a/components/libc/minilibc/ctype.h
+++ b/components/libc/minilibc/ctype.h
@@ -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
diff --git a/components/libc/minilibc/stdlib.c b/components/libc/minilibc/stdlib.c
index cac4ae5691..7185f56bb7 100644
--- a/components/libc/minilibc/stdlib.c
+++ b/components/libc/minilibc/stdlib.c
@@ -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);
diff --git a/components/libc/minilibc/stdlib.h b/components/libc/minilibc/stdlib.h
index 9ff5cdd86c..08f7e0d07b 100644
--- a/components/libc/minilibc/stdlib.h
+++ b/components/libc/minilibc/stdlib.h
@@ -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);