Files
osc2025/lib/string.c
2025-04-08 06:59:49 +08:00

55 lines
911 B
C

#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;
}
char *strcpy(char *destination, const char *source)
{
char *ret = destination;
while (*source != '\0')
*destination++ = *source++;
*destination = '\0';
return ret;
}
size_t strlen(const char *str)
{
size_t ret = 0;
while (*str != '\0')
++ret, ++str;
return ret;
}
void *memcpy(void *dest, const void *src, size_t count)
{
void *ret = dest;
for (const uint8_t *p = src; count > 0; --count, ++p, ++dest)
*(uint8_t *)dest = *p;
return ret;
}
void *memzero(void *start, void *end)
{
void *ret = start;
for (uint8_t *p = start; p < (uint8_t *)end; ++p)
*p = 0;
return ret;
}