initial commit
This commit is contained in:
35
lib/string.c
Normal file
35
lib/string.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
int strcmp(const char *a, const char *b)
|
||||
{
|
||||
while (*a != '\0' && *b != '\0') {
|
||||
if (*a != *b)
|
||||
return (*a > *b) - (*a < *b);
|
||||
a++, b++;
|
||||
}
|
||||
if (*a == '\0' && *b == '\0')
|
||||
return 0;
|
||||
|
||||
if (*a == '\0')
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t count)
|
||||
{
|
||||
void *ret = dest;
|
||||
for (const byte_t *p = src; count > 0; --count, ++p, ++dest)
|
||||
*(byte_t *)dest = *p;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *memzero(void *start, void *end)
|
||||
{
|
||||
void *ret = start;
|
||||
for (byte_t *p = start; p < (byte_t *)end; ++p)
|
||||
*p = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user