File: tryboottime.c

package info (click to toggle)
ngetty 1.0-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 304 kB
  • ctags: 207
  • sloc: ansic: 1,503; makefile: 236; sh: 109; asm: 100
file content (17 lines) | stat: -rw-r--r-- 422 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <time.h>

int main() {
#if defined(CTL_KERN) && defined(KERN_BOOTTIME)
  /* FreeBSD specific: fetch sysctl "kern.boottime". */
  struct timeval res = { 0, 0 };
  int req[2] = { CTL_KERN, KERN_BOOTTIME };
  size_t res_len = sizeof res;
  if (sysctl(req, 2, &res, &res_len, 0, 0) >= 0 && res.tv_sec > 0)
    return 0;
#else
  return -1;
#endif
}