diff options
Diffstat (limited to 'macosx/uptime.c')
-rw-r--r-- | macosx/uptime.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/macosx/uptime.c b/macosx/uptime.c new file mode 100644 index 00000000..7146fb52 --- /dev/null +++ b/macosx/uptime.c @@ -0,0 +1,17 @@ +#include <time.h> +#include <errno.h> +#include <sys/sysctl.h> + +long uptime(void) +{ + struct timeval boottime; + size_t len = sizeof(boottime); + int mib[2] = { CTL_KERN, KERN_BOOTTIME }; + if (sysctl(mib, 2, &boottime, &len, NULL, 0) < 0) + { + return -1L; + } + time_t bsec = boottime.tv_sec, csec = time(NULL); + + return (long) difftime(csec, bsec); +} |