Add sysctlbyname() for MacOS

This commit is contained in:
Justine Tunney 2024-05-02 23:21:43 -07:00
parent 5c6877b02b
commit 181cd4cbe8
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
21 changed files with 193 additions and 35 deletions

View file

@ -74,9 +74,9 @@ char *GetInterpreterExecutableName(char *p, size_t n) {
cmd[2] = 12; // KERN_PROC_PATHNAME
} else { //
cmd[2] = 5; // KERN_PROC_PATHNAME
} //
cmd[3] = -1; // current process
if (sys_sysctl(cmd, ARRAYLEN(cmd), p, &n, 0, 0) != -1) {
} //
cmd[3] = -1; // current process
if (sysctl(cmd, ARRAYLEN(cmd), p, &n, 0, 0) != -1) {
errno = e;
return p;
}

View file

@ -23,7 +23,7 @@ long __get_sysctl(int x, int y) {
int value;
int mib[2] = {x, y};
size_t len = sizeof(value);
if (sys_sysctl(mib, 2, &value, &len, 0, 0) != -1) {
if (sysctl(mib, 2, &value, &len, 0, 0) != -1) {
return value;
} else {
return -1;

View file

@ -12,7 +12,7 @@ COSMOPOLITAN_C_START_
#define SYSLIB_MAGIC ('s' | 'l' << 8 | 'i' << 16 | 'b' << 24)
#define SYSLIB_VERSION 9 /* sync with ape/ape-m1.c */
#define SYSLIB_VERSION 10 /* sync with ape/ape-m1.c */
/* if this number increases, then everyone on macos arm will need to
reinstall ape loader in order to run newer ape binaries so please
@ -82,6 +82,9 @@ struct Syslib {
char *(*__dlerror)(void);
/* v9 (2024-01-31) */
int (*__pthread_cpu_number_np)(size_t *);
long (*__sysctl)(int *, unsigned, void *, size_t *, void *, size_t);
long (*__sysctlbyname)(const char *, void *, size_t *, void *, size_t);
long (*__sysctlnametomib)(const char *, int *, size_t *);
};
extern struct Syslib *__syslib;