summaryrefslogtreecommitdiff
path: root/lib/gettimeofday.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gettimeofday.c')
-rw-r--r--lib/gettimeofday.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c
index d896ec132b..69b43a62c8 100644
--- a/lib/gettimeofday.c
+++ b/lib/gettimeofday.c
@@ -113,8 +113,10 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
ULONGLONG since_1970 =
since_1601 - (ULONGLONG) 134774 * (ULONGLONG) 86400 * (ULONGLONG) 10000000;
ULONGLONG microseconds_since_1970 = since_1970 / (ULONGLONG) 10;
- tv->tv_sec = microseconds_since_1970 / (ULONGLONG) 1000000;
- tv->tv_usec = microseconds_since_1970 % (ULONGLONG) 1000000;
+ *tv = (struct timeval) {
+ .tv_sec = microseconds_since_1970 / (ULONGLONG) 1000000,
+ .tv_usec = microseconds_since_1970 % (ULONGLONG) 1000000
+ };
return 0;
@@ -127,10 +129,7 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
struct timeval otv;
int result = gettimeofday (&otv, (struct timezone *) tz);
if (result == 0)
- {
- tv->tv_sec = otv.tv_sec;
- tv->tv_usec = otv.tv_usec;
- }
+ *tv = otv;
# else
int result = gettimeofday (tv, (struct timezone *) tz);
# endif
@@ -143,8 +142,7 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
# error "Only 1-second nominal clock resolution found. Is that intended?" \
"If so, compile with the -DOK_TO_USE_1S_CLOCK option."
# endif
- tv->tv_sec = time (NULL);
- tv->tv_usec = 0;
+ *tv = (struct timeval) { .tv_sec = time (NULL) };
return 0;