diff options
author | pommicket <pommicket@gmail.com> | 2022-02-19 12:01:56 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-02-19 12:01:56 -0500 |
commit | 9c6b9a1450d6610a37234b016bc1cfb021f30ee8 (patch) | |
tree | 9416b9c6b13b30f9107030cdccca7b33b1b27d60 /05/stdlib.h | |
parent | 59b7931165ecbd189214142b95d3d2033f4f579f (diff) |
full build of tcc with itself - doesn't match gcc :o
Diffstat (limited to '05/stdlib.h')
-rw-r--r-- | 05/stdlib.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/05/stdlib.h b/05/stdlib.h index b93d4aa..cbfd0b5 100644 --- a/05/stdlib.h +++ b/05/stdlib.h @@ -73,12 +73,25 @@ void *realloc(void *ptr, size_t size) { free(ptr); return NULL; } +#if 0 + // this (better) implementation doesn't seem to be copying stuff to the + // new mapping properly uint64_t *memory = (char *)ptr - 16; uint64_t old_size = *memory; uint64_t *new_memory = _mremap(memory, old_size, size, MREMAP_MAYMOVE); if ((uint64_t)new_memory > 0xffffffffffff0000) return NULL; *new_memory = size; return (char *)new_memory + 16; +#endif + + uint64_t *memory = (char *)ptr - 16; + uint64_t old_size = *memory; + void *new = malloc(size); + char *new_dat = (char *)new + 16; + *(uint64_t *)new = size; + memcpy(new_dat, ptr, old_size); + free(ptr); + return new_dat; } |