mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-09-02 18:31:12 +02:00
The start point of the monotonic clock is undefined, but in practice
it is often zero. There is lots of code that does not assume that a
timestamp can be that low and then fails in subtle ways.
Add a 7 day offset to the clock value to work around that.
git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@1271 e54a6e83-5905-42d5-8d5c-058d10e6a962
Origin commit data
------------------
Branch: ni/coolstream
Commit: e78a89520d
Author: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: 2011-03-07 (Mon, 07 Mar 2011)
------------------
This commit was generated by Migit
30 lines
654 B
C
30 lines
654 B
C
#include <stdio.h> /* for perror */
|
|
#include <time.h>
|
|
|
|
time_t time_monotonic_ms(void)
|
|
{
|
|
struct timespec t;
|
|
time_t ret;
|
|
if (clock_gettime(CLOCK_MONOTONIC, &t))
|
|
{
|
|
perror("time_monotonic_ms clock_gettime");
|
|
return -1;
|
|
}
|
|
ret = ((t.tv_sec + 604800)& 0x01FFFFF) * 1000; /* avoid overflow */
|
|
ret += t.tv_nsec / 1000000;
|
|
return ret;
|
|
}
|
|
|
|
time_t time_monotonic(void)
|
|
{
|
|
struct timespec t;
|
|
if (clock_gettime(CLOCK_MONOTONIC, &t))
|
|
{
|
|
perror("time_monotonic clock_gettime");
|
|
return -1;
|
|
}
|
|
/* CLOCK_MONOTONIC is often == uptime, so starts at 0. Bad for relative
|
|
time comparisons if the uptime is low, so add 7 days */
|
|
return t.tv_sec + 604800;
|
|
}
|