mblaze

Unix utilities to deal with Maildir - my mirror
git clone https://pi.duncano.de/git/mblaze.git
Log | Files | Refs | README | COPYING

commit 6b9f742d7d1c8c7e691bcd42f801c286d6df4bee
parent d21ab392e99ef0a5a1b3382136fe94c784adf5b3
Author: Leah Neukirchen <leah@vuxu.org>
Date:   Sun, 26 Mar 2017 19:03:16 +0200

mgenmid: use gettimeofday instead of clock_gettime

Fixes #17.

Nanosecond precision wasn't needed, and many legacy operating systems
don't support this POSIX.1-2001 function.

We now use plain microseconds for the timestamp, which uses the range of
the 64-bit number better as well.  This will result in a Year 294247 problem.

Diffstat:
mgenmid.c | 9+++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/mgenmid.c b/mgenmid.c @@ -1,5 +1,6 @@ #include <sys/socket.h> #include <sys/stat.h> +#include <sys/time.h> #include <sys/types.h> #include <fcntl.h> @@ -80,8 +81,8 @@ int main() exit(1); } - struct timespec tp; - clock_gettime(CLOCK_REALTIME, &tp); + struct timeval tp; + gettimeofday(&tp, (struct timezone *)0); uint64_t rnd; @@ -97,14 +98,14 @@ int main() rnd = rnd*256 + rndb[i]; } else { fallback: - srand48(tp.tv_sec ^ tp.tv_nsec/1000 ^ getpid()); + srand48(tp.tv_sec ^ tp.tv_usec ^ getpid()); rnd = (lrand48() << 32) + lrand48(); } rnd |= (1LL << 63); // set highest bit to force full width putchar('<'); - printb36(((uint64_t)tp.tv_sec << 16) + (tp.tv_nsec >> 16)); + printb36(((uint64_t)tp.tv_sec * 1000000LL + tp.tv_usec)); putchar('.'); printb36(rnd); putchar('@');