blob: 119e7dff8ff141f49bfabff0e62e9fc0eb7cc4d4 [file] [log] [blame] [raw]
/*
htop - bsd/Platform.c
(C) 2014 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include <sys/param.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <time.h>
int Platform_getUptime() {
struct timeval bootTime, currTime;
int mib[2] = { CTL_KERN, KERN_BOOTTIME };
size_t size = sizeof(bootTime);
if(sysctl(mib, 2, &bootTime, &size, NULL, 0) < 0) return -1;
if(gettimeofday(&currTime, NULL) < 0) return -1;
return (int) difftime(currTime.tv_sec, bootTime.tv_sec);
}