+ return TIME_CHECK(t);
+}
+
+struct timespec time_from_nsec(uint64_t nsec)
+{
+ struct timespec t;
+
+ t.tv_nsec = nsec % 1000000000;
+ t.tv_sec = nsec / 1000000000;
+ return TIME_CHECK(t);
+}
+
+struct timespec time_check(struct timespec t, const char *abortstr)
+{
+ if (t.tv_sec < 0 || t.tv_nsec >= 1000000000) {
+ if (abortstr) {
+ fprintf(stderr, "%s: malformed time %li.%09li\n",
+ abortstr,
+ (long)t.tv_sec, (long)t.tv_nsec);
+ abort();
+ } else {
+ struct timespec old = t;
+
+ if (t.tv_nsec >= 1000000000) {
+ t.tv_sec += t.tv_nsec / 1000000000;
+ t.tv_nsec %= 1000000000;
+ }
+ if (t.tv_sec < 0)
+ t.tv_sec = 0;
+
+ fprintf(stderr, "WARNING: malformed time"
+ " %li seconds %li ns converted to %li.%09li.\n",
+ (long)old.tv_sec, (long)old.tv_nsec,
+ (long)t.tv_sec, (long)t.tv_nsec);
+ }
+ }