[go: up one dir, main page]

Menu

[205fcb]: / src / timetag.c  Maximize  Restore  History

Download this file

64 lines (56 with data), 1.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (C) 2004 Steve Harris
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* $Id$
*/
#include "lo_types_internal.h"
#include "lo/lo.h"
#ifdef USE_ANSI_C
lo_timetag lo_get_tt_immediate()
{
lo_timetag tt = { 0U, 1U };
return tt;
}
#endif
#ifndef _MSC_VER
#include <sys/time.h>
#endif
#include <time.h>
#define JAN_1970 0x83aa7e80 /* 2208988800 1970 - 1900 in seconds */
double lo_timetag_diff(lo_timetag a, lo_timetag b)
{
return (double) a.sec - (double) b.sec +
((double) a.frac - (double) b.frac) * 0.00000000023283064365;
}
void lo_timetag_now(lo_timetag * t)
{
#if defined(WIN32) || defined(_MSC_VER)
/*
FILETIME is the time in units of 100 nsecs from 1601-Jan-01
1601 and 1900 are 9435484800 seconds apart.
*/
FILETIME ftime;
double dtime;
GetSystemTimeAsFileTime(&ftime);
dtime =
((ftime.dwHighDateTime * 4294967296.e-7) - 9435484800.) +
(ftime.dwLowDateTime * 1.e-7);
t->sec = (uint32_t) dtime;
t->frac = (uint32_t) ((dtime - t->sec) * 4294967296.);
#else
struct timeval tv;
gettimeofday(&tv, NULL);
t->sec = tv.tv_sec + JAN_1970;
t->frac = tv.tv_usec * 4294.967295;
#endif
}