-int
-timestamp_set(int fd, int secs)
-{
- struct timespec mono, real, ts_mono, ts_real, timeout;
-
- if (clock_gettime(CLOCK_MONOTONIC_RAW, &mono) == -1 ||
- clock_gettime(CLOCK_REALTIME, &real) == -1)
- err(1, "clock_gettime");
-
- memset(&timeout, 0, sizeof timeout);
- timeout.tv_sec = secs;
- timespecadd(&timeout, &mono, &ts_mono);
- timespecadd(&timeout, &real, &ts_real);
-
- if (lseek(fd, 0, SEEK_SET) == -1)
- err(1, "lseek");
- if (ftruncate(fd, 0) == -1)
- err(1, "ftruncate");
- if (write(fd, (void *)&ts_mono, sizeof ts_mono) != sizeof ts_mono ||
- write(fd, (void *)&ts_real, sizeof ts_real) != sizeof ts_real)
- err(1, "write");
-
- return 0;
-}
-