Skip to content

Commit

Permalink
Fixes preprocessor condition so mac build compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
julman99 committed Oct 14, 2015
1 parent 3e050b2 commit 45e6b0d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions eatmemory.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#include <stdbool.h>
#include <unistd.h>

#ifdef _SC_PHYS_PAGES
#if defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES) && defined(_SC_PAGE_SIZE)
#define MEMORY_PERCENTAGE
#endif

#ifdef MEMORY_PERCENTAGE
size_t getTotalSystemMemory(){
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
Expand Down Expand Up @@ -40,7 +44,7 @@ bool eat(long total,int chunk){

int main(int argc, char *argv[]){

#ifdef _SC_PHYS_PAGES
#ifdef MEMORY_PERCENTAGE
printf("Currently total memory: %zd\n",getTotalSystemMemory());
printf("Currently avail memory: %zd\n",getFreeSystemMemory());
#endif
Expand All @@ -54,7 +58,7 @@ int main(int argc, char *argv[]){
printf("# # Bytes example: 1024\n");
printf("#M # Megabytes example: 15M\n");
printf("#G # Gigabytes example: 2G\n");
#ifdef _SC_PHYS_PAGES
#ifdef MEMORY_PERCENTAGE
printf("#%% # Percent example: 50%%\n");
#endif
printf("\n");
Expand All @@ -68,7 +72,7 @@ int main(int argc, char *argv[]){
arg[len-1]=0;
size=atol(arg) * (unit=='M'?1024*1024:1024*1024*1024);
}
#ifdef _SC_PHYS_PAGES
#ifdef MEMORY_PERCENTAGE
else if (unit=='%') {
size = (atol(arg) * (long)getFreeSystemMemory())/100;
}
Expand Down

0 comments on commit 45e6b0d

Please sign in to comment.