Add calloc
This commit is contained in:
parent
23b2e53038
commit
e3e73279fc
|
|
@ -0,0 +1,13 @@
|
||||||
|
If:
|
||||||
|
PathMatch: .*\.cpp
|
||||||
|
|
||||||
|
CompileFlags:
|
||||||
|
Add: [-std=c++23]
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
If:
|
||||||
|
PathMatch: .*\.c
|
||||||
|
|
||||||
|
CompileFlags:
|
||||||
|
Add: [-std=c23]
|
||||||
|
|
@ -16,11 +16,12 @@ extern unsigned char __heap_base;
|
||||||
#define IMPORT(name) __attribute__((import_module("env"), import_name(#name)))
|
#define IMPORT(name) __attribute__((import_module("env"), import_name(#name)))
|
||||||
#define EXPORT(name) __attribute__((export_name(#name)))
|
#define EXPORT(name) __attribute__((export_name(#name)))
|
||||||
|
|
||||||
void* malloc(size_t);
|
void* malloc(size_t size);
|
||||||
void free(void*);
|
void* calloc(size_t n, size_t size);
|
||||||
void* realloc(void*, size_t);
|
void* realloc(void* ptr, size_t size);
|
||||||
|
void free(void* ptr);
|
||||||
|
|
||||||
void* memset(void* d, uint8_t c, size_t n);
|
void* memset(void* dest, uint8_t ch, size_t n);
|
||||||
void* memcpy(void* dest, const void* src, size_t n);
|
void* memcpy(void* dest, const void* src, size_t n);
|
||||||
int memcmp(const void* s1, const void* s2, size_t n);
|
int memcmp(const void* s1, const void* s2, size_t n);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,20 @@ void* realloc(void* block, size_t size) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* calloc(size_t n, size_t size) {
|
||||||
|
const size_t s = n * size;
|
||||||
|
if (s == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* ret = malloc(n * size);
|
||||||
|
if (ret) {
|
||||||
|
memset(ret, 0, n * size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void* memset(void* d, uint8_t c, size_t n) {
|
void* memset(void* d, uint8_t c, size_t n) {
|
||||||
uint8_t* p = (uint8_t*)d;
|
uint8_t* p = (uint8_t*)d;
|
||||||
while (n--) {
|
while (n--) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
--target=wasm32
|
--target=wasm32
|
||||||
-std=gnu++23
|
|
||||||
-fno-builtin
|
-fno-builtin
|
||||||
--no-standard-libraries
|
--no-standard-libraries
|
||||||
-I
|
-I
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue