Debian Codegraph @

src/include/timeops.h

raw
1 // ----------------------------------------------------------------------------
2 // Copyright (C) 2014
3 // David Freese, W1HKJ
4 //
5 // This file is part of flmsg
6 //
7 // fldigi is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // fldigi is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 // ----------------------------------------------------------------------------
20
21 #ifndef TIMEOPS_H_
22 #define TIMEOPS_H_
23
24 #include <config.h>
25 #include <time.h>
26 #include <sys/time.h>
27
28 #ifdef __MINGW32__
29 # include "compat.h"
30 # include <pthread.h>
31 #endif
32
33 #ifdef __APPLE__
34 # if __DARWIN_C_LEVEL < 199309L
35 # if!HAVE_CLOCK_GETTIME
36 // enum clockid_t { CLOCK_REALTIME, CLOCK_MONOTONIC };
37 # ifndef __clockid_t_defined
38 typedef int clockid_t;
39 #define __clockid_t_defined 1
40 # endif /* __clockid_t_defined */
41
42 # ifndef CLOCK_REALTIME
43 # define CLOCK_REALTIME 0
44 # endif
45
46 # ifndef CLOCK_MONOTONIC
47 # define CLOCK_MONOTONIC 1
48 # endif
49
50 int clock_gettime(clockid_t clock_id, struct timespec* tp);
51 # endif /* !HAVE_CLOCK_GETTIME */
52
53 # endif /* __DARWIN_C_LEVEL */
54
55 #else
56
57 # if !HAVE_CLOCK_GETTIME
58 // enum clockid_t { CLOCK_REALTIME, CLOCK_MONOTONIC };
59 # ifndef __clockid_t_defined
60 typedef int clockid_t;
61 #define __clockid_t_defined 1
62 # endif /* __clockid_t_defined */
63
64 # ifndef CLOCK_REALTIME
65 # define CLOCK_REALTIME 0
66 # endif
67
68 # ifndef CLOCK_MONOTONIC
69 # define CLOCK_MONOTONIC 1
70 # endif
71
72 int clock_gettime(clockid_t clock_id, struct timespec* tp);
73 # endif /* !HAVE_CLOCK_GETTIME */
74
75 #endif /* __APPLE__ */
76
77
78 struct timespec operator+(const struct timespec &t0, const double &t);
79 struct timespec operator-(const struct timespec &t0, const struct timespec &t1);
80 struct timespec& operator-=(struct timespec &t0, const struct timespec &t1);
81 bool operator>(const struct timespec &t0, const struct timespec &t1);
82 bool operator==(const struct timespec &t0, const struct timespec &t1);
83
84 struct timeval operator+(const struct timeval &t0, const double &t);
85 struct timeval operator-(const struct timeval &t0, const struct timeval &t1);
86 struct timeval& operator-=(struct timeval &t0, const struct timeval &t1);
87 bool operator>(const struct timeval &t0, const struct timeval &t1);
88 bool operator==(const struct timeval &t0, const struct timeval &t1);
89
90 #ifndef GMTIME_R
91 extern struct tm *gmtime_r(const time_t *timer, struct tm *tmbuf);
92 extern struct tm *localtime_r(const time_t *_Time,struct tm *_Tm);
93 #endif
94
95 #endif // TIMEOPS_H_