本文整理汇总了C++中TIMESPEC_TO_TIMEVAL函数的典型用法代码示例。如果您正苦于以下问题:C++ TIMESPEC_TO_TIMEVAL函数的具体用法?C++ TIMESPEC_TO_TIMEVAL怎么用?C++ TIMESPEC_TO_TIMEVAL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TIMESPEC_TO_TIMEVAL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_utimes
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);
}
示例2: setfile
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);
}
示例3: processvattr
/*
* 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;
}
示例4: usbi_cond_timedwait
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);
}
示例5: usbi_cond_timedwait
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);
}
示例6: stime_file
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);
}
示例7: set_utimes
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);
}
示例8: watchdog_check_dogfunction_time
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);
}
示例9: setfile
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);
}
示例10: set_ftime
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);
}
示例11: get_boot_time
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;
}
示例12: ioport_sleep
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
}
示例13: __select
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;
}
示例14: nanosleep
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);
}
示例15: WRITEFDS
/* 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;
}