int set_utimes(const char *file, struct stat *fs) { static struct timeval tv[2]; #ifndef BSD tv[0].tv_sec = fs->st_atime; tv[0].tv_usec = 0; tv[1].tv_sec = fs->st_mtime; tv[1].tv_usec = 0; if (utimes(file, tv)) { warn("utimes: %s", file); return 1; } #else TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec); TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec); if (lutimes(file, tv)) { warn("lutimes: %s", file); return (1); } #endif return (0); }
static void setfile(const char *name, struct stat *fs) { static struct timeval tv[2]; fs->st_mode &= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO; TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atim); TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtim); if (utimes(name, tv)) cwarn("utimes: %s", name); /* * Changing the ownership probably won't succeed, unless we're root * or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting * the mode; current BSD behavior is to remove all setuid bits on * chown. If chown fails, lose setuid/setgid bits. */ if (chown(name, fs->st_uid, fs->st_gid)) { if (errno != EPERM) cwarn("chown: %s", name); fs->st_mode &= ~(S_ISUID|S_ISGID); } if (chmod(name, fs->st_mode) && errno != EOPNOTSUPP) cwarn("chmod: %s", name); if (chflags(name, fs->st_flags) && errno != EOPNOTSUPP) cwarn("chflags: %s", name); }
/* * set attributes to what is specified. XXX: no rollback in case of failure */ static int processvattr(const char *path, const struct vattr *va, int regular) { struct timeval tv[2]; /* XXX: -1 == PUFFS_VNOVAL, but shouldn't trust that */ if (va->va_uid != (unsigned)-1 || va->va_gid != (unsigned)-1) if (lchown(path, va->va_uid, va->va_gid) == -1) return errno; if (va->va_mode != (u_short)PUFFS_VNOVAL) if (lchmod(path, va->va_mode) == -1) return errno; /* sloppy */ if (va->va_atime.tv_sec != (time_t)PUFFS_VNOVAL || va->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL) { TIMESPEC_TO_TIMEVAL(&tv[0], &va->va_atime); TIMESPEC_TO_TIMEVAL(&tv[1], &va->va_mtime); if (lutimes(path, tv) == -1) return errno; } if (regular && va->va_size != (u_quad_t)PUFFS_VNOVAL) if (truncate(path, (off_t)va->va_size) == -1) return errno; return 0; }
int usbi_cond_timedwait(usbi_cond_t *cond, usbi_mutex_t *mutex, const struct timespec *abstime) { FILETIME filetime; ULARGE_INTEGER rtime; struct timeval targ_time, cur_time, delta_time; struct timespec cur_time_ns; DWORD millis; // GetSystemTimeAsFileTime() is not available on CE SYSTEMTIME st; GetSystemTime(&st); SystemTimeToFileTime(&st, &filetime); rtime.LowPart = filetime.dwLowDateTime; rtime.HighPart = filetime.dwHighDateTime; rtime.QuadPart -= epoch_time; cur_time_ns.tv_sec = (long)(rtime.QuadPart / 10000000); cur_time_ns.tv_nsec = (long)((rtime.QuadPart % 10000000)*100); TIMESPEC_TO_TIMEVAL(&cur_time, &cur_time_ns); TIMESPEC_TO_TIMEVAL(&targ_time, abstime); timersub(&targ_time, &cur_time, &delta_time); if(delta_time.tv_sec < 0) // abstime already passed? millis = 0; else { millis = delta_time.tv_usec/1000; millis += delta_time.tv_sec *1000; if (delta_time.tv_usec % 1000) // round up to next millisecond millis++; } return usbi_cond_intwait(cond, mutex, millis); }
int usbi_cond_timedwait(usbi_cond_t *cond, usbi_mutex_t *mutex, const struct timespec *abstime) { FILETIME filetime; ULARGE_INTEGER rtime; struct timeval targ_time, cur_time, delta_time; struct timespec cur_time_ns; DWORD millis; extern const uint64_t epoch_time; GetSystemTimeAsFileTime(&filetime); rtime.LowPart = filetime.dwLowDateTime; rtime.HighPart = filetime.dwHighDateTime; rtime.QuadPart -= epoch_time; cur_time_ns.tv_sec = (long)(rtime.QuadPart / 10000000); cur_time_ns.tv_nsec = (long)((rtime.QuadPart % 10000000)*100); TIMESPEC_TO_TIMEVAL(&cur_time, &cur_time_ns); TIMESPEC_TO_TIMEVAL(&targ_time, abstime); timersub(&targ_time, &cur_time, &delta_time); if(delta_time.tv_sec < 0) millis = 0; else { millis = delta_time.tv_usec/1000; millis += delta_time.tv_sec *1000; if (delta_time.tv_usec % 1000) millis++; } return usbi_cond_intwait(cond, mutex, millis); }
void stime_file(char *fname, struct timeval *tvp) { struct stat sb; if (stat(fname, &sb)) err(1, "%s", fname); TIMESPEC_TO_TIMEVAL(tvp, &sb.st_atimespec); TIMESPEC_TO_TIMEVAL(tvp + 1, &sb.st_mtimespec); }
/* * Please Call this function only from the call back functions of the alarm_handler. * This is just a hack */ int dd_timer_change_settime( timer_t timerid, /* timer ID */ const struct itimerspec *value /* time to be * set */ ) { struct event *event = ( struct event * )timerid; TIMESPEC_TO_TIMEVAL( &event->it_interval, &value->it_interval ); TIMESPEC_TO_TIMEVAL( &event->it_value, &value->it_value ); return 1; }
int set_utimes(const char *file, struct stat *fs) { static struct timeval tv[2]; TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec); TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec); if (lutimes(file, tv)) { warn("lutimes: %s", file); return (1); } return (0); }
FileIO::Status FileIO::saveTimes(const char *filename, FileTimes ×) { struct stat stats; if (filename == NULL) return Error; if (stat(filename, &stats) == -1) { warn("%s: Could not stat file", filename); return Error; } TIMESPEC_TO_TIMEVAL(×.access, &stats.st_atim); TIMESPEC_TO_TIMEVAL(×.modification, &stats.st_mtim); return Success; }
static long watchdog_check_dogfunction_time(struct timespec *tp_start, struct timespec *tp_end) { struct timeval tv_start, tv_end, tv_now, tv; const char *cmd_prefix, *cmd; struct timespec tp_now; int sec; if (!do_timedog) return (0); TIMESPEC_TO_TIMEVAL(&tv_start, tp_start); TIMESPEC_TO_TIMEVAL(&tv_end, tp_end); timersub(&tv_end, &tv_start, &tv); sec = tv.tv_sec; if (sec < carp_thresh_seconds) return (sec); if (test_cmd) { cmd_prefix = "Watchdog program"; cmd = test_cmd; } else { cmd_prefix = "Watchdog operation"; cmd = "stat(\"/etc\", &sb)"; } if (do_syslog) syslog(LOG_CRIT, "%s: '%s' took too long: " "%d.%06ld seconds >= %d seconds threshold", cmd_prefix, cmd, sec, (long)tv.tv_usec, carp_thresh_seconds); else warnx("%s: '%s' took too long: " "%d.%06ld seconds >= %d seconds threshold", cmd_prefix, cmd, sec, (long)tv.tv_usec, carp_thresh_seconds); /* * Adjust the sleep interval again in case syslog(3) took a non-trivial * amount of time to run. */ if (watchdog_getuptime(&tp_now)) return (sec); TIMESPEC_TO_TIMEVAL(&tv_now, &tp_now); timersub(&tv_now, &tv_start, &tv); sec = tv.tv_sec; return (sec); }
int setfile(struct stat *fs, int fd) { static struct timeval tv[2]; int rval; rval = 0; fs->st_mode &= S_ISTXT | S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO; TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec); TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec); if (utimes(to.p_path, tv)) { warn("utimes: %s", to.p_path); rval = 1; } /* * Changing the ownership probably won't succeed, unless we're root * or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting * the mode; current BSD behavior is to remove all setuid bits on * chown. If chown fails, lose setuid/setgid bits. */ if (fd ? fchown(fd, fs->st_uid, fs->st_gid) : chown(to.p_path, fs->st_uid, fs->st_gid)) { if (errno != EPERM) { warn("chown: %s", to.p_path); rval = 1; } fs->st_mode &= ~(S_ISTXT | S_ISUID | S_ISGID); } if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) { warn("chmod: %s", to.p_path); rval = 1; } /* * XXX * NFS doesn't support chflags; ignore errors unless there's reason * to believe we're losing bits. (Note, this still won't be right * if the server supports flags and we were trying to *remove* flags * on a file that we copied, i.e., that we didn't create.) */ errno = 0; if (fd ? fchflags(fd, fs->st_flags) : chflags(to.p_path, fs->st_flags)) if (errno != EOPNOTSUPP || fs->st_flags != 0) { warn("chflags: %s", to.p_path); rval = 1; } return (rval); }
void set_ftime(char *fnm, time_t mtime, time_t atime, int frc, int slk) { struct timeval tv[2]; struct stat sb; tv[0].tv_sec = atime; tv[0].tv_usec = 0; tv[1].tv_sec = mtime; tv[1].tv_usec = 0; if (!frc && (!patime || !pmtime)) { /* * if we are not forcing, only set those times the user wants * set. We get the current values of the times if we need them. */ if (lstat(fnm, &sb) == 0) { #if BSD4_4 && !HAVE_NBTOOL_CONFIG_H if (!patime) TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atimespec); if (!pmtime) TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec); #else if (!patime) tv[0].tv_sec = sb.st_atime; if (!pmtime) tv[1].tv_sec = sb.st_mtime; #endif } else syswarn(0, errno, "Cannot obtain file stats %s", fnm); } /* * set the times */ #if HAVE_LUTIMES if (lutimes(fnm, tv) == 0) return; if (errno != ENOSYS) /* XXX linux: lutimes is per-FS */ goto bad; #endif if (slk) return; if (utimes(fnm, tv) == -1) goto bad; return; bad: syswarn(1, errno, "Access/modification time set failed on: %s", fnm); }
int get_boot_time(struct timeval *boot_time) { #ifdef CLOCK_BOOTTIME struct timespec hires_uptime; struct timeval lores_uptime; #endif struct timeval now; struct sysinfo info; if (gettimeofday(&now, NULL) != 0) { warn(_("gettimeofday failed")); return -errno; } #ifdef CLOCK_BOOTTIME if (clock_gettime(CLOCK_BOOTTIME, &hires_uptime) == 0) { TIMESPEC_TO_TIMEVAL(&lores_uptime, &hires_uptime); timersub(&now, &lores_uptime, boot_time); return 0; } #endif /* fallback */ if (sysinfo(&info) != 0) warn(_("sysinfo failed")); boot_time->tv_sec = now.tv_sec - info.uptime; boot_time->tv_usec = 0; return 0; }
void ioport_sleep(const struct timespec UNUSED(nap)) { #ifdef HAVE_IOPERM uint32_t usec; struct timeval nap_for; time_t i; TIMESPEC_TO_TIMEVAL(&nap_for, &nap); /* * process the seconds, we do this in a loop so we don't have to * use slower 64bit integers or worry about integer overflows. */ for (i = 0; i < nap_for.tv_sec; i ++) { usec = SEC_TO_MICROSEC(nap_for.tv_sec); while (usec > 0) { usec --; outb(ioport_sleep_value, 0x80); } } /* process the usec */ usec = nap.tv_nsec / 1000; usec --; /* fudge factor for all the above */ while (usec > 0) { usec --; outb(ioport_sleep_value, 0x80); } #else err(-1, "Platform does not support IO Port for timing"); #endif }
int __select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { int result; struct timespec ts, *tsp = NULL; if (timeout) { TIMEVAL_TO_TIMESPEC (timeout, &ts); tsp = &ts; } result = SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds, tsp, NULL); if (timeout) { /* Linux by default will update the timeout after a pselect6 syscall (though the pselect() glibc call suppresses this behavior). Since select() on Linux has the same behavior as the pselect6 syscall, we update the timeout here. */ TIMESPEC_TO_TIMEVAL (timeout, &ts); } return result; }
int nanosleep(const struct timespec *req, struct timespec *rem) { int rc, saverrno; extern int errno; struct timeval tstart, tstop, tremain, time2wait; TIMESPEC_TO_TIMEVAL(&time2wait, req) (void) gettimeofday(&tstart, NULL); rc = select(0, NULL, NULL, NULL, &time2wait); if (rc == -1) { saverrno = errno; (void) gettimeofday (&tstop, NULL); errno = saverrno; tremain.tv_sec = time2wait.tv_sec - (tstop.tv_sec - tstart.tv_sec); tremain.tv_usec = time2wait.tv_usec - (tstop.tv_usec - tstart.tv_usec); tremain.tv_sec += tremain.tv_usec / 1000000L; tremain.tv_usec %= 1000000L; } else { tremain.tv_sec = 0; tremain.tv_usec = 0; } TIMEVAL_TO_TIMESPEC(&tremain, rem) return(rc); }
/* Check the first NFDS descriptors each in READFDS (if not NULL) for read readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out after waiting the interval specified therein. Additionally set the sigmask SIGMASK for this call. Returns the number of ready descriptors, or -1 for errors. */ int pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask) { struct timeval tval; int retval; sigset_t savemask; /* Change nanosecond number to microseconds. This might mean losing precision and therefore the `pselect` should be available. But for now it is hardly found. */ if (timeout != NULL) TIMESPEC_TO_TIMEVAL (&tval, timeout); /* The setting and restoring of the signal mask and the select call should be an atomic operation. This can't be done without kernel help. */ if (sigmask != NULL) sigprocmask (SIG_SETMASK, sigmask, &savemask); /* Note the pselect() is a cancellation point. But since we call select() which itself is a cancellation point we do not have to do anything here. */ retval = select (nfds, readfds, writefds, exceptfds, timeout != NULL ? &tval : NULL); if (sigmask != NULL) sigprocmask (SIG_SETMASK, &savemask, NULL); return retval; }
static inline int tstohz(const struct timespec *tsp) { struct timeval tv; TIMESPEC_TO_TIMEVAL(&tv, tsp); return (tvtohz(&tv)); }
int main(int argc, char **argv) { int ret; test_issue_128(); test_sleep(1, 0, 1, 0); test_nanosleep(0, 0, 0, 1000); /*if 0 time is passed it should take anyway 1 microsecond*/ test_nanosleep(0, 1998, 0, 1998); test_select_timeout(0, 0, 0, 1000); test_select_timeout(0, 1000, 0, 1000); { struct timespec ts, ts2; struct timeval tv_inc, tv, tv2; /*compare time before and after select, measure in nanoseconds*/ TEST_OPERATION_RESULT( clock_gettime(CLOCK_REALTIME, &ts), &ret, ret==0 ); /*select can only wait for timeout when no file descriptors specified*/ struct timeval timeout; timeout.tv_sec = 1; timeout.tv_usec = 1000; TEST_OPERATION_RESULT( select(0, NULL, NULL, NULL, &timeout), &ret, ret==0); timeout.tv_usec += 1; /*clock_gettime done +1 microsecond*/ TEST_OPERATION_RESULT( clock_gettime(CLOCK_REALTIME, &ts2), &ret, ret==0 ); TIMESPEC_TO_TIMEVAL(&tv, &ts); TIMESPEC_TO_TIMEVAL(&tv2, &ts2); timeradd(&tv, &timeout, &tv_inc); TEST_OPERATION_RESULT( timercmp(&tv_inc, &tv2, <= ), &ret, ret==1); /*select's synchronous multiplexing is supported now*/ fd_set readfds; FD_ZERO (&readfds); FD_SET (0, &readfds); TEST_OPERATION_RESULT( select(FD_SETSIZE, &readfds, NULL, NULL, &timeout), &ret, errno!=ENOSYS&&ret!=0); } return 0; }
void complete_nanosec_test(struct timespec *prepared_ts, struct timespec *timeout_ts){ int ret; struct timespec new_ts; timeout_ts->tv_nsec += 1000; /*clock_gettime take additional time*/ TEST_OPERATION_RESULT( clock_gettime(CLOCK_REALTIME, &new_ts), &ret, ret==0 ); struct timeval prepared_tv; TIMESPEC_TO_TIMEVAL(&prepared_tv, prepared_ts); struct timeval new_tv; TIMESPEC_TO_TIMEVAL(&new_tv, &new_ts); struct timeval timeout_tv; TIMESPEC_TO_TIMEVAL(&timeout_tv, timeout_ts); struct timeval tv_inc; timeradd(&prepared_tv, &timeout_tv, &tv_inc); TEST_OPERATION_RESULT( timercmp(&tv_inc, &new_tv, <= ), &ret, ret==1); }
/* Get the current date and time into a struct timeval */ int gettimeofday(struct timeval *ptv, void *pTimeZone) { struct timespec ts; int iErr; if (pTimeZone) pTimeZone = 0; /* Ignore it, and prevent compilation warning */ iErr = clock_gettime(CLOCK_REALTIME, &ts); if (iErr) return iErr; TIMESPEC_TO_TIMEVAL(ptv, &ts); return 0; }
int setfile(struct stat *fs, int fd) { static struct timeval tv[2]; struct stat ts; int rval, gotstat, islink, fdval; rval = 0; fdval = fd != -1; islink = !fdval && S_ISLNK(fs->st_mode); fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO; TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atim); TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtim); if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) { warn("%sutimes: %s", islink ? "l" : "", to.p_path); rval = 1; } if (fdval ? fstat(fd, &ts) : (islink ? lstat(to.p_path, &ts) : stat(to.p_path, &ts))) gotstat = 0; else { gotstat = 1; ts.st_mode &= S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO; } if (!gotstat || fs->st_uid != ts.st_uid || fs->st_gid != ts.st_gid) if (fdval ? fchown(fd, fs->st_uid, fs->st_gid) : (islink ? lchown(to.p_path, fs->st_uid, fs->st_gid) : chown(to.p_path, fs->st_uid, fs->st_gid))) { if (errno != EPERM) { warn("chown: %s", to.p_path); rval = 1; } fs->st_mode &= ~(S_ISUID | S_ISGID); } if (!gotstat || fs->st_mode != ts.st_mode) if (fdval ? fchmod(fd, fs->st_mode) : (islink ? lchmod(to.p_path, fs->st_mode) : chmod(to.p_path, fs->st_mode))) { warn("chmod: %s", to.p_path); rval = 1; } if (!gotstat || fs->st_flags != ts.st_flags) if (fdval ? fchflags(fd, fs->st_flags) : (islink ? lchflags(to.p_path, fs->st_flags) : chflags(to.p_path, fs->st_flags))) { warn("chflags: %s", to.p_path); rval = 1; } return (rval); }
/* * set the owner, mode, flags & utimes using the given file descriptor. * file is only used in possible warning messages. */ static void copymodes(int fd, const struct stat *sbp, const char *file) { struct timeval times[2]; struct stat sb; /* * If we have no info on the input, give this file some * default values and return.. */ if (sbp == NULL) { mode_t mask = umask(022); (void)fchmod(fd, DEFFILEMODE & ~mask); (void)umask(mask); return; } sb = *sbp; /* if the chown fails, remove set-id bits as-per compress(1) */ if (fchown(fd, sb.st_uid, sb.st_gid) < 0) { if (errno != EPERM) maybe_warn("couldn't fchown: %s", file); sb.st_mode &= ~(S_ISUID|S_ISGID); } /* we only allow set-id and the 9 normal permission bits */ sb.st_mode &= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO; if (fchmod(fd, sb.st_mode) < 0) maybe_warn("couldn't fchmod: %s", file); /* only try flags if they exist already */ #ifndef __minix if (sb.st_flags != 0 && fchflags(fd, sb.st_flags) < 0) maybe_warn("couldn't fchflags: %s", file); #endif TIMESPEC_TO_TIMEVAL(×[0], &sb.st_atimespec); TIMESPEC_TO_TIMEVAL(×[1], &sb.st_mtimespec); #ifndef __minix if (futimes(fd, times) < 0) maybe_warn("couldn't utimes: %s", file); #endif }
/* ------------------------------------------------------------------------- * * struct timeval helpers * ------------------------------------------------------------------------- */ static void tv_get_monotime(struct timeval *tv) { #if defined(CLOCK_BOOTTIME) struct timespec ts; if (clock_gettime(CLOCK_BOOTTIME, &ts) < 0) if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) qFatal("Can't clock_gettime!"); TIMESPEC_TO_TIMEVAL(tv, &ts); #endif }
static int pow2ns_to_ticks(int pow2ns) { struct timeval tv; struct timespec ts; pow2ns_to_ts(pow2ns, &ts); TIMESPEC_TO_TIMEVAL(&tv, &ts); return (tvtohz(&tv)); }
void setfile(const char *name, int fd, struct stat *fs) { struct timeval tv[2]; if (name == NULL || cat || testmode) return; /* * If input was a pipe we don't have any info to restore but we * must set the mode since the current mode on the file is 0200. */ if (pipin) { mode_t mask = umask(022); fchmod(fd, DEFFILEMODE & ~mask); umask(mask); return; } /* * Changing the ownership probably won't succeed, unless we're root * or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting * the mode; current BSD behavior is to remove all setuid bits on * chown. If chown fails, lose setuid/setgid bits. */ fs->st_mode &= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO; if (fchown(fd, fs->st_uid, fs->st_gid)) { if (errno != EPERM) warn("fchown: %s", name); fs->st_mode &= ~(S_ISUID|S_ISGID); } if (fchmod(fd, fs->st_mode)) warn("fchmod: %s", name); if (fs->st_flags && fchflags(fd, fs->st_flags)) warn("fchflags: %s", name); TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec); TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec); if (futimes(fd, tv)) warn("futimes: %s", name); }
bool PlatformFile::getFileTimes(PlatformTime& times) { if (!isValid()) { return false; } struct stat file; if (::fstat(handle_, &file) < 0) { return false; } #if defined(__linux__) TIMESPEC_TO_TIMEVAL(×.times[0], &file.st_atim); TIMESPEC_TO_TIMEVAL(×.times[1], &file.st_mtim); #else TIMESPEC_TO_TIMEVAL(×.times[0], &file.st_atimespec); TIMESPEC_TO_TIMEVAL(×.times[1], &file.st_mtimespec); #endif return true; }
/* * Write system time back to RTC */ void oskit_rtc_set(struct oskit_timespec *time) { struct timeval t; struct timespec ts; memcpy(&ts, time, sizeof ts); /* MST to greenwich */ t.tv_sec += 6 * 60 * 60; TIMESPEC_TO_TIMEVAL(&t, &ts); NATIVEOS(settimeofday)(&t, 0); }
int do_sleep(struct timespec *delay, struct timespec *remain) { struct timeval tv; TIMESPEC_TO_TIMEVAL(&tv, delay); remain->tv_sec = sleep(delay->tv_sec); remain->tv_nsec = 0; return 0; }
int set_utimes(const char *file, struct stat *fs) { static struct timeval tv[2]; #ifndef HAVE_STRUCT_STAT_ST_ATIMESPEC tv[0].tv_sec = fs->st_atime; tv[0].tv_usec = 0; tv[1].tv_sec = fs->st_mtime; tv[1].tv_usec = 0; #else TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec); TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec); #endif if (lutimes(file, tv)) { warn("lutimes: %s", file); return (1); } return (0); }