hippOS/std/std.c

43 lines
936 B
C
Raw Normal View History

#include "std/std.h"
size_t strlen(const char* str) {
size_t len = 0;
while (str[len])
len++;
return len;
}
int memcmp(const void *av, const void *bv, size_t size) {
const unsigned char *a = (const unsigned char*) av;
const unsigned char *b = (const unsigned char*) bv;
for (size_t i = 0; i < size; i++) {
if (a[i] < b[i]) {
return -1;
} else if (b[i] < a[i]) {
return 1;
}
}
return 0;
}
void* memset(void *bufv, int value, size_t size) {
unsigned char* buf = (unsigned char*) buf;
for (size_t i = 0; i < size; i++) {
buf[i] = (unsigned char) value;
}
return bufv;
}
void* memcpy(void *destv, void *srcv, size_t size) {
unsigned char *dest = (unsigned char*) destv;
const unsigned char *src = (unsigned char*) srcv;
for (size_t i = 0; i < size; i++) {
dest[i] = src[i];
}
return destv;
}