diff options
Diffstat (limited to 'miniany/libc-freestanding.c')
-rw-r--r-- | miniany/libc-freestanding.c | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/miniany/libc-freestanding.c b/miniany/libc-freestanding.c index 8b1a378..ffed093 100644 --- a/miniany/libc-freestanding.c +++ b/miniany/libc-freestanding.c @@ -20,6 +20,40 @@ int strlen( char *s ) return p - s; } +int strcmp( char *s1, char *s2 ) +{ + while( ( *s1 != '\0' ) && ( *s2 != '\0' ) && *s1 == *s2 ) { + s1++; + s2++; + } + + return *s1 - *s2; +} + +int isspace( int c ) +{ + if( c == ' ' || c == '\r' || c == '\n' || c == '\t' ) return 1; + return 0; +} + +int isdigit( int c ) +{ + if( c >= '0' && c <= '9' ) return 1; + return 0; +} + +int isalpha( int c ) +{ + if( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) ) return 1; + return 0; +} + +int isalnum( int c ) +{ + if( isalpha( c ) || isdigit( c ) ) return 1; + return 0; +} + enum { EXIT_SUCCESS = 0, EXIT_FAILURE = 1 @@ -31,9 +65,18 @@ enum { SYSCALL_WRITE = 4 }; +/* EOF = -1 is a const expression for c4 */ +/* EOF = 0xFFFFFFFF clang doesn't like this */ +/* EOF = 0xFFFFFFFF gcc overflow in conversion from 'enum <anonymous>' to 'int' changes value from '4294967295' to '-1' */ +/* EOF = 256, this is not standard, but doesn't really matter in freestanding mode, + * code should really not relly on the fact what the value of EOF is (-1 usually) */ +enum { + EOF = 256 +}; + int errno; -static __attribute__((noinline)) int syscall1( int id, int arg0 ) +int syscall1( int id, int arg0 ) { int retval; @@ -54,7 +97,7 @@ static __attribute__((noinline)) int syscall1( int id, int arg0 ) return retval; } -static __attribute__((noinline)) int syscall3( int id, int arg0, int arg1, int arg2 ) +int syscall3( int id, int arg0, int arg1, int arg2 ) { int retval; @@ -109,10 +152,6 @@ static int read_string( int fd, char *buf, int size ) return syscall3( SYSCALL_READ, fd, (int)buf, size ); } -enum { - EOF = -1 -}; - int puts( char *s ) { print_string( s ); |