Browse Source

add atol and isspace to minilibc.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2218 bbd45198-f89e-11dd-88c7-29a3b14d5316
qiuyiuestc@gmail.com 13 years ago
parent
commit
70cee4b82e

+ 17 - 1
components/libc/minilibc/ctype.c

@@ -31,7 +31,23 @@ int isalpha(int ch)
 
 
 int isdigit (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
 #endif

+ 1 - 0
components/libc/minilibc/ctype.h

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

+ 17 - 0
components/libc/minilibc/stdlib.c

@@ -37,6 +37,23 @@ int atoi(const char* s)
 	return sign==-1?-v:v;
 	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)
 void *malloc(size_t size)
 {
 {
 	return rt_malloc(size);
 	return rt_malloc(size);

+ 1 - 0
components/libc/minilibc/stdlib.h

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