luxos/Kernel/library/stdlib/str_ops.c
Tiberiu Chibici 852cf1bb17 [GOOD] BUILD 0.1.0.590 DATE 9/05/2011 AT 2:40 PM
====================================================
Mainly changed: FS.Initrd
+ (kind of) refractored VFS, bugfixed
+ Rewrote 'initrd' file system, fixed many problems
+ Working 'cat' and 'dir' console commands
+ Wrote 'initrd' image write application (for windows), however it may
be bugged
2021-09-14 18:52:47 +03:00

86 lines
1.4 KiB
C

/*
* str_ops.c
*
* Created on: Aug 27, 2011
* Author: Tiberiu
*/
#include <types.h>
#include <ctype.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));
}
int32 strncmp (string a, string b, uint32 n)
{
unsigned char uc1, uc2;
if (!n) return 0;
while (n-- > 0 && *a == *b) {
if (n == 0 || (*a == *b && *a == '\0')) return 0;
a++; b++;
}
uc1 = (* (unsigned char*)a);
uc2 = (* (unsigned char*)b);
return ((uc1 < uc2) ? -1 : (uc1 > uc2));
}
int32 strcasecmp (string a, string b)
{
unsigned char c1, c2;
while (*a != '\0' && *b != '\0' && tolower(*a) == tolower(*b)) {
a++; b++;
}
c1 = tolower(*(unsigned char*) a);
c2 = tolower(*(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;
}