diff --git a/zealbooter/lib.h b/zealbooter/lib.h index 50795a1d..4092ce5e 100644 --- a/zealbooter/lib.h +++ b/zealbooter/lib.h @@ -3,6 +3,9 @@ #include #include +#include +#include +#include #include uint64_t div_roundup_u64(uint64_t a, uint64_t b); diff --git a/zealbooter/lib/memcmp.c b/zealbooter/lib/memcmp.c new file mode 100644 index 00000000..dd406ae2 --- /dev/null +++ b/zealbooter/lib/memcmp.c @@ -0,0 +1,26 @@ +/* memcmp( const void *, const void *, size_t ) + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +int memcmp(const void *s1, const void *s2, size_t n) +{ + const unsigned char *p1 = (const unsigned char *)s1; + const unsigned char *p2 = (const unsigned char *)s2; + + while (n--) + { + if (*p1 != *p2) + { + return *p1 - *p2; + } + + ++p1; + ++p2; + } + + return 0; +} + diff --git a/zealbooter/lib/memcmp.h b/zealbooter/lib/memcmp.h new file mode 100644 index 00000000..3bbc4ca7 --- /dev/null +++ b/zealbooter/lib/memcmp.h @@ -0,0 +1,6 @@ +#ifndef __MEMCMP_H__ +#define __MEMCMP_H__ + +int memcmp(const void *s1, const void *s2, size_t n); + +#endif // __MEMCMP_H__ diff --git a/zealbooter/lib/memmove.c b/zealbooter/lib/memmove.c new file mode 100644 index 00000000..040402b4 --- /dev/null +++ b/zealbooter/lib/memmove.c @@ -0,0 +1,33 @@ +/* memmove( void *, const void *, size_t ) + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +void *memmove(void *s1, const void *s2, size_t n) +{ + char *dest = (char *)s1; + const char *src = (const char *)s2; + + if (dest <= src) + { + while (n--) + { + *dest++ = *src++; + } + } + else + { + src += n; + dest += n; + + while (n--) + { + *--dest = *--src; + } + } + + return s1; +} + diff --git a/zealbooter/lib/memmove.h b/zealbooter/lib/memmove.h new file mode 100644 index 00000000..80d5cba6 --- /dev/null +++ b/zealbooter/lib/memmove.h @@ -0,0 +1,6 @@ +#ifndef __MEMMOVE_H__ +#define __MEMMOVE_H__ + +void *memmove(void *s1, const void *s2, size_t n); + +#endif // __MEMMOVE_H__ diff --git a/zealbooter/lib/memset.c b/zealbooter/lib/memset.c new file mode 100644 index 00000000..cf951f09 --- /dev/null +++ b/zealbooter/lib/memset.c @@ -0,0 +1,20 @@ +/* memset( void *, int, size_t ) + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +void *memset(void *s, int c, size_t n) +{ + unsigned char *p = (unsigned char *)s; + + while (n--) + { + *p++ = (unsigned char)c; + } + + return s; +} + + diff --git a/zealbooter/lib/memset.h b/zealbooter/lib/memset.h new file mode 100644 index 00000000..78fcb588 --- /dev/null +++ b/zealbooter/lib/memset.h @@ -0,0 +1,6 @@ +#ifndef __MEMSET_H__ +#define __MEMSET_H__ + +void *memset(void *s, int c, size_t n); + +#endif // __MEMSET_H__