diff options
Diffstat (limited to 'src/system.c')
-rw-r--r-- | src/system.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/system.c b/src/system.c index bd3df98..d62b42f 100644 --- a/src/system.c +++ b/src/system.c @@ -2,6 +2,23 @@ #define _NETBSD_SOURCE #endif +#if __APPLE__ +// don't play with POSIX and Darwin flags, they don't work! +// they are defined in unistd.h, but enabling flags breaks other +// system header files! +#define _SC_NPROCESSORS_ONLN 58 +#define _SC_PAGESIZE 29 +#define _SC_PHYS_PAGES 200 +#include <unistd.h> +#include <stdint.h> +typedef unsigned long u_long; +typedef unsigned int u_int; +typedef unsigned char u_char; +typedef unsigned short u_short; +#include <sys/types.h> +#include <sys/sysctl.h> +#endif /* __APPLE__ */ + #include "system.h" #include "port.h" @@ -355,6 +372,11 @@ void system_os( char *name, size_t len ) struct utsname uts; uname( &uts ); snprintf( name, len, "cpe:/o:%s:%s:%s", uts.sysname, uts.release, uts.version ); +#elif defined( __APPLE__ ) + /* resort to uname */ + struct utsname uts; + uname( &uts ); + snprintf( name, len, "cpe:/o:apple:osx:%s", uts.release ); #else /* TODO: or should this be a compilation error? */ snprintf( name, len, "cpe:/o:unknown:unknown:unknown" ); @@ -410,6 +432,11 @@ unsigned int system_phys_memory( ) memState.dwLength = sizeof( MEMORYSTATUSEX ); GlobalMemoryStatusEx( &memState ); return memState.ullTotalPhys / 1024; +#elif defined( __APPLE__ ) + uint64_t mem; + size_t len = sizeof( mem ); + sysctlbyname( "hw.memsize", &mem, &len, NULL, 0 ); + return mem / 1024; #elif defined( linux ) || defined( __linux ) || defined( __linux__ ) || defined( __FreeBSD__ ) || defined( __NetBSD__ ) size_t pageSize; size_t nofPages; |