Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions code/sys/sys_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <time.h>
#include <sys/resource.h>

#if defined (__linux__)
#include <sys/sysinfo.h>
#endif

#if defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__APPLE__)
#include <sys/sysctl.h>
#include <sys/types.h>
#endif

qboolean stdinIsATTY;

static char execBuffer[ 1024 ];
Expand Down Expand Up @@ -595,7 +604,33 @@ TODO
*/
qboolean Sys_LowPhysicalMemory( void )
{
#if defined (__linux__)
struct sysinfo info;

if ( sysinfo(&info) == -1 )
return qfalse;

return info.totalram <= MEM_THRESHOLD;
#elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__APPLE__)
#if defined (__FreeBSD__)
int mib[2] = { CTL_HW, HW_PHYSMEM };
#elif defined (__OpenBSD__)
int mib[2] = { CTL_HW, HW_PHYSMEM64 };
#elif defined (__APPLE__)
int mib[2] = { CTL_HW, HW_MEMSIZE };
#endif

size_t len;
int64_t total_mem;

len = sizeof(int64_t);
if ( sysctl(mib, 2, &total_mem, &len, NULL, 0) == -1 )
return qfalse;

return total_mem <= MEM_THRESHOLD;
#else
return qfalse;
#endif
}

/*
Expand Down