Commit 8108c8f3 authored by Mathieu Maret's avatar Mathieu Maret

klibc: add string related func

parent e998fec7
......@@ -55,3 +55,35 @@ char * itoa( int value, char * str, int base )
}
return rc;
}
/* K&R */
void reverse(char s[])
{
int c, i, j;
for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
/* K&R */
int strlen(char s[])
{
int i = 0;
while (s[i] != '\0')
++i;
return i;
}
/* K&R
* Returns <0 if s1<s2, 0 if s1==s2, >0 if s1>s2 */
int strcmp(char s1[], char s2[])
{
int i;
for (i = 0; s1[i] == s2[i]; i++) {
if (s1[i] == '\0')
return 0;
}
return s1[i] - s2[i];
}
......@@ -4,3 +4,6 @@
void *memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
char *itoa(int value, char *str, int base);
void reverse(char s[]);
int strlen(char s[]);
int strcmp(char s1[], char s2[]);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment