67 lines
959 B
C
67 lines
959 B
C
/*
|
|
* Copyright (c) 2013-2014 Stanford University
|
|
* Copyright (c) 2006-2008 Ali Mashtizadeh
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
char *
|
|
strcpy(char *to, const char *from)
|
|
{
|
|
char *save = to;
|
|
|
|
for (; (*to = *from); ++from, ++to);
|
|
|
|
return save;
|
|
}
|
|
|
|
int
|
|
strcmp(const char *s1, const char *s2)
|
|
{
|
|
while (*s1 == *s2++)
|
|
if (*s1++ == 0)
|
|
return 0;
|
|
|
|
return (*(const uint8_t *)s1 - *(const uint8_t *)(s2 - 1));
|
|
}
|
|
|
|
size_t
|
|
strlen(const char *str)
|
|
{
|
|
const char *s;
|
|
|
|
for (s = str; *s; ++s);
|
|
|
|
return (s - str);
|
|
}
|
|
|
|
void *
|
|
memset(void *dst, int c, size_t length)
|
|
{
|
|
uint8_t *p = (uint8_t *)dst;
|
|
|
|
do {
|
|
*p = c;
|
|
p += 1;
|
|
} while (--length != 0);
|
|
|
|
return dst;
|
|
}
|
|
|
|
void *
|
|
memcpy(void *dst, const void *src, size_t length)
|
|
{
|
|
uint8_t *d = (uint8_t *)dst;
|
|
const uint8_t *s = (const uint8_t *)src;
|
|
|
|
do {
|
|
*d = *s;
|
|
d += 1;
|
|
s += 1;
|
|
} while (--length != 0);
|
|
|
|
return dst;
|
|
}
|
|
|