70 lines
1.3 KiB
C
70 lines
1.3 KiB
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;
|
|
}
|
|
|
|
char *strtok_r(char *restrict str, const char *restrict delimiters,
|
|
char **restrict saveptr)
|
|
{
|
|
if (str)
|
|
*saveptr = str;
|
|
for (char *ret = *saveptr; **saveptr != '\0'; ++(*saveptr)) {
|
|
for (int i = 0; delimiters[i] != '\0'; i++)
|
|
if (**saveptr == delimiters[i]) {
|
|
*(*saveptr)++ = '\0';
|
|
return ret;
|
|
}
|
|
}
|
|
return 0x0;
|
|
}
|
|
|
|
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;
|
|
}
|