Organize libc and libm files (#1499)

* memmove

* strcpy

* strcmp

* memset

* fmodf

* fix some missing includes

* Remove libc header dependencies on libultra

* fix

* review
This commit is contained in:
Anghelo Carvajal
2023-11-27 23:01:14 -03:00
committed by GitHub
parent 2fdcdd91b3
commit 7649cd309a
22 changed files with 77 additions and 59 deletions
-11
View File
@@ -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;
}
@@ -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;
+12
View File
@@ -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;
}
@@ -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;
}
@@ -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') {
+3 -3
View File
@@ -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);
@@ -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;