diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2023-11-27 23:01:14 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-28 13:01:14 +1100 |
| commit | 7649cd309af155de1b8ee8bfd32d850e46f27925 (patch) | |
| tree | 8c66e552901046c002e951691fb063bf5be2b00f /src/boot | |
| parent | 2fdcdd91b332d234a823e43607978e010152b811 (diff) | |
Organize `libc` and `libm` files (#1499)
* memmove
* strcpy
* strcmp
* memset
* fmodf
* fix some missing includes
* Remove libc header dependencies on libultra
* fix
* review
Diffstat (limited to 'src/boot')
| -rw-r--r-- | src/boot/O2/__osMemset.c | 11 | ||||
| -rw-r--r-- | src/boot/libc/memmove.c (renamed from src/boot/O2/__osMemcpy.c) | 10 | ||||
| -rw-r--r-- | src/boot/libc/memset.c | 12 | ||||
| -rw-r--r-- | src/boot/libc/strcmp.c (renamed from src/boot/O2/__osStrcmp.c) | 9 | ||||
| -rw-r--r-- | src/boot/libc/strcpy.c (renamed from src/boot/O2/__osStrcpy.c) | 4 | ||||
| -rw-r--r-- | src/boot/libc64/__osMalloc.c | 6 | ||||
| -rw-r--r-- | src/boot/libm/fmodf.c (renamed from src/boot/O2/fmodf.c) | 6 |
7 files changed, 30 insertions, 28 deletions
diff --git a/src/boot/O2/__osMemset.c b/src/boot/O2/__osMemset.c deleted file mode 100644 index 0c4172e9f..000000000 --- a/src/boot/O2/__osMemset.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "global.h" - -void* __osMemset(void* ptr, s32 val, size_t size) { - u8* dst = ptr; - register s32 rem; - - for (rem = size--; rem != 0; rem = size--) { - *dst++ = val; - } - return ptr; -} diff --git a/src/boot/O2/__osMemcpy.c b/src/boot/libc/memmove.c index 2e25b23f0..720de0fac 100644 --- a/src/boot/O2/__osMemcpy.c +++ b/src/boot/libc/memmove.c @@ -1,9 +1,9 @@ -#include "global.h" +#include "libc/string.h" -void* __osMemcpy(void* dst, void* src, size_t size) { - u8* _dst = dst; - u8* _src = src; - register s32 rem; +void* memmove(void* dst, const void* src, size_t size) { + unsigned char* _dst = dst; + const unsigned char* _src = src; + register size_t rem; if (_dst == _src) { return dst; diff --git a/src/boot/libc/memset.c b/src/boot/libc/memset.c new file mode 100644 index 000000000..7e0b1c0ed --- /dev/null +++ b/src/boot/libc/memset.c @@ -0,0 +1,12 @@ +#include "libc/string.h" + +void* memset(void* ptr, int val, size_t size) { + unsigned char* dst = ptr; + register size_t rem; + + for (rem = size--; rem != 0; rem = size--) { + *dst++ = val; + } + + return ptr; +} diff --git a/src/boot/O2/__osStrcmp.c b/src/boot/libc/strcmp.c index 10bd2fa92..d65e4411f 100644 --- a/src/boot/O2/__osStrcmp.c +++ b/src/boot/libc/strcmp.c @@ -1,12 +1,13 @@ -#include "global.h" +#include "libc/string.h" -s32 __osStrcmp(const char* str1, const char* str2) { - char c1; - char c2; +int strcmp(const char* str1, const char* str2) { + unsigned char c1; + unsigned char c2; do { c1 = *str1++; c2 = *str2++; + if (c1 != c2) { return c1 - c2; } diff --git a/src/boot/O2/__osStrcpy.c b/src/boot/libc/strcpy.c index 86a98a804..8166a47e0 100644 --- a/src/boot/O2/__osStrcpy.c +++ b/src/boot/libc/strcpy.c @@ -1,6 +1,6 @@ -#include "global.h" +#include "libc/string.h" -char* __osStrcpy(char* dst, const char* src) { +char* strcpy(char* dst, const char* src) { char* _dst = dst; while (*src != '\0') { diff --git a/src/boot/libc64/__osMalloc.c b/src/boot/libc64/__osMalloc.c index 2c736740b..554008997 100644 --- a/src/boot/libc64/__osMalloc.c +++ b/src/boot/libc64/__osMalloc.c @@ -1,10 +1,10 @@ #include "libc64/os_malloc.h" #include "alignment.h" -#include "functions.h" // for __osMemcpy #include "libc/stdbool.h" #include "libc/stdint.h" -#include "macros.h" // for ARRAY_COUNT +#include "libc/string.h" +#include "macros.h" #define FILL_ALLOCBLOCK (1 << 0) #define FILL_FREEBLOCK (1 << 1) @@ -374,7 +374,7 @@ void* __osRealloc(Arena* arena, void* ptr, size_t newSize) { next2 = (void*)((uintptr_t)next + diff); node->next = next2; node->size = newSize; - __osMemcpy(next2, next, sizeof(ArenaNode)); + memmove(next2, next, sizeof(ArenaNode)); } else { // Create a new pointer and manually copy the data from the old pointer to the new one newPtr = __osMalloc(arena, newSize); diff --git a/src/boot/O2/fmodf.c b/src/boot/libm/fmodf.c index 2f8aa74bf..0c2df736d 100644 --- a/src/boot/O2/fmodf.c +++ b/src/boot/libm/fmodf.c @@ -1,7 +1,7 @@ -#include "global.h" +#include "libc/math.h" -f32 fmodf(f32 dividend, f32 divisor) { - s32 quotient; +float fmodf(float dividend, float divisor) { + int quotient; if (divisor == 0.0f) { return 0.0f; |
