kern
diff src/klibc/string.c @ 5:633e35c64772
- added printf family in stdio.c
- added atoi/atol in stdlib.c
- added nonstandard itoa/utoa in stdlib.c
- added strlen/strchr/strrchr in string.c
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 19 Dec 2010 15:07:07 +0200 |
parents | 0489a34ab348 |
children | af6f4adc43d6 |
line diff
1.1 --- a/src/klibc/string.c Fri Dec 10 03:44:34 2010 +0200 1.2 +++ b/src/klibc/string.c Sun Dec 19 15:07:07 2010 +0200 1.3 @@ -54,3 +54,37 @@ 1.4 1.5 return dest; 1.6 } 1.7 + 1.8 +size_t strlen(const char *s) 1.9 +{ 1.10 + size_t len = 0; 1.11 + while(*s++) len++; 1.12 + return len; 1.13 +} 1.14 + 1.15 +char *strchr(const char *s, int c) 1.16 +{ 1.17 + while(*s) { 1.18 + if(*s == c) { 1.19 + return s; 1.20 + } 1.21 + s++; 1.22 + } 1.23 + return 0; 1.24 +} 1.25 + 1.26 +char *strrchr(const char *s, int c) 1.27 +{ 1.28 + char *ptr = s; 1.29 + 1.30 + /* find the end */ 1.31 + while(*ptr) ptr++; 1.32 + 1.33 + /* go back checking for c */ 1.34 + while(*--ptr >= s) { 1.35 + if(*ptr == c) { 1.36 + return ptr; 1.37 + } 1.38 + } 1.39 + return 0; 1.40 +}