From c9e2ed3038fa4ddba549e4a1dd2e7e4fa3c5fbce Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Wed, 7 May 2014 15:02:51 +0930 Subject: [PATCH] time_ms_to_timeval() --- os.c | 12 +++++++++--- os.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/os.c b/os.c index 1e6b3817..c72a4f6f 100644 --- a/os.c +++ b/os.c @@ -166,6 +166,14 @@ time_ms_t sleep_ms(time_ms_t milliseconds) return remain.tv_sec * 1000 + remain.tv_nsec / 1000000; } +struct timeval time_ms_to_timeval(time_ms_t milliseconds) +{ + struct timeval tv; + tv.tv_sec = milliseconds / 1000; + tv.tv_usec = (milliseconds % 1000) * 1000; + return tv; +} + ssize_t read_symlink(const char *path, char *buf, size_t len) { if (len == 0) { @@ -320,9 +328,7 @@ int alter_file_meta(const char *path, const struct file_meta *origp, struct file meta.mtime = origp->mtime; add_timespec(&meta.mtime, sec, nsec); struct timeval times[2]; - time_ms_t now = gettime_ms(); - times[0].tv_sec = now / 1000; - times[0].tv_usec = (now % 1000) * 1000; + times[0] = time_ms_to_timeval(gettime_ms()); times[1].tv_sec = meta.mtime.tv_sec; times[1].tv_usec = meta.mtime.tv_nsec / 1000; if (utimes(path, times) == -1) diff --git a/os.h b/os.h index 86c59c3d..c6f8c933 100644 --- a/os.h +++ b/os.h @@ -61,6 +61,7 @@ typedef int64_t time_ms_t; time_ms_t gettime_ms(); time_ms_t sleep_ms(time_ms_t milliseconds); +struct timeval time_ms_to_timeval(time_ms_t); #ifndef HAVE_BZERO __SERVAL_DNA__OS_INLINE void bzero(void *buf, size_t len) {