Implement system polyfill for win32 / posix.1

I don't have access to Microsoft Visual Studio right now (aside from the
the Github Actions CI system) but I think this code should come close to
what we want in terms of polyfilling UNIX functionality.
This commit is contained in:
Justine Tunney
2023-03-17 21:22:40 -07:00
parent 5b8023d935
commit 0b5448a3a4
2 changed files with 264 additions and 22 deletions

View File

@@ -1,9 +1,9 @@
#include "ggml.h"
#include "utils.h"
#include "mmap.h"
#include <cassert>
#include <cerrno>
#include <cmath>
#include <cstdio>
#include <cstring>
@@ -207,27 +207,6 @@ void *memalign(size_t a, size_t n) {
return p;
}
int posix_memalign(void **pp, size_t a, size_t n) {
int e;
void *m;
size_t q, r;
q = a / sizeof(void *);
r = a % sizeof(void *);
if (!r && q && IS2POW(q)) {
e = errno;
m = memalign(a, n);
if (m) {
*pp = m;
return 0;
} else {
errno = e;
return ENOMEM;
}
} else {
return EINVAL;
}
}
void *malloc(size_t n) {
return memalign(MAGIC_ALGN, n);
}