luxos/Kernel/library/stdlib/str_ops.c

57 lines
857 B
C

/*
* str_ops.c
*
* Created on: Aug 27, 2011
* Author: Tiberiu
*/
#include <types.h>
uint32 strlen (string s)
{
string end = s;
while (*end != '\0')
end++;
return (uint32)(end - s);
}
int32 strcmp (string a, string b)
{
unsigned char c1, c2;
while (*a != '\0' && *b != '\0' && *a == *b) {
a++; b++;
}
c1 = (*(unsigned char*) a);
c2 = (*(unsigned char*) b);
return ((c1 < c2) ? -1 : (c1 > c2));
}
string strcpy (string s1, const string s2)
{
char *dst = s1;
const char *src = s2;
while ((*dst++ = *src++) != '\0') ;
return s1;
}
char* strchr (string s, int c)
{
while (*s != '\0' && *s != (char)c) s++;
return ((*s == (char)c) ? (char*)s : NULL);
}
char* strrchr (string s, int c)
{
string last = NULL;
if (c == '\0') return strchr(s, c);
while ((s = strchr(s, c)) != NULL)
last = s; s++;
return (char*)last;
}