klibc: add string related func

This commit is contained in:
Mathieu Maret 2018-11-20 17:03:57 +01:00
parent e998fec795
commit 8108c8f3ab
2 changed files with 35 additions and 0 deletions

View File

@ -55,3 +55,35 @@ char * itoa( int value, char * str, int base )
} }
return rc; 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];
}

View File

@ -4,3 +4,6 @@
void *memcpy(void *dest, const void *src, size_t n); void *memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n); void *memset(void *s, int c, size_t n);
char *itoa(int value, char *str, int base); char *itoa(int value, char *str, int base);
void reverse(char s[]);
int strlen(char s[]);
int strcmp(char s1[], char s2[]);