/*
 * moduptime.c
 *
 * For FreeBSD 2.2.6, possibly others...
 * Tristan Horn <tristan+c@ethereal.net>
 * May 18, 1998
 *
 */

#include <sys/time.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sysexits.h>

int main(int argc, char **argv) {
  struct timeval boottime;
  size_t size = sizeof(boottime);
  int mib[CTL_MAXNAME];

  mib[0] = CTL_KERN;
  mib[1] = KERN_BOOTTIME;

  if (argc < 2)
    exit(EX_USAGE);

  if (sysctl(mib, 2, &boottime, &size, 0, 0) != -1) {
    boottime.tv_sec = atoi(argv[1]);
    if (argv[2])
      boottime.tv_usec = atoi(argv[2]);
    if (sysctl(mib, 2, 0, 0, &boottime, size))
      perror("sysctl");
  }

  return(EX_OK);
}
