From c03d5d4bfc92e48ea1781db82a29f33b2a69f151 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Mon, 23 Apr 2018 21:47:50 +0200 Subject: fixed for OSX 10.8.0 using MacPorts --- src/GNUmakefile | 2 +- src/system.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/GNUmakefile b/src/GNUmakefile index 9ae594c..440c56f 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -26,7 +26,7 @@ biruda: biruda.o biruda_cmdline.o master.o coordinator.o worker.o system.o webse $(CC) -o $@ $(LDFLAGS) $^ $(LIBS) birudaenv: birudaenv.c system.c - $(CC) -static -o $@ $^ + $(CC) -o $@ $^ biruda_cmdline.o: biruda_cmdline.c biruda.o: biruda.c biruda_cmdline.h master.h coordinator.h worker.h port.h system.h webserver.h 3rdParty/linenoise/linenoise.h cli.h biruda_conf.c 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 +#include +typedef unsigned long u_long; +typedef unsigned int u_int; +typedef unsigned char u_char; +typedef unsigned short u_short; +#include +#include +#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; -- cgit v1.2.3-54-g00ecf