Imported Upstream version 1.1.11
[platform/upstream/cdrkit.git] / include / timedefs.h
1 /*
2  * This file has been modified for the cdrkit suite.
3  *
4  * The behaviour and appearence of the program code below can differ to a major
5  * extent from the version distributed by the original author(s).
6  *
7  * For details, see Changelog file distributed with the cdrkit package. If you
8  * received this file from another source then ask the distributing person for
9  * a log of modifications.
10  *
11  */
12
13 /* @(#)timedefs.h       1.13 05/08/22 Copyright 1996 J. Schilling */
14 /*
15  *      Generic header for users of time(), gettimeofday() ...
16  *
17  *      It includes definitions for time_t, struct timeval, ...
18  *
19  *      Copyright (c) 1996 J. Schilling
20  */
21 /*
22  * This program is free software; you can redistribute it and/or modify
23  * it under the terms of the GNU General Public License version 2
24  * as published by the Free Software Foundation.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29  * GNU General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License along with
32  * this program; see the file COPYING.  If not, write to the Free Software
33  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34  */
35
36 #ifndef _TIMEDEFS_H
37 #define _TIMEDEFS_H
38
39 #ifndef _MCONFIG_H
40 #include <mconfig.h>
41 #endif
42
43 #ifndef _INCL_SYS_TYPES_H
44 #include <sys/types.h>          /* Needed for time_t            */
45 #define _INCL_SYS_TYPES_H
46 #endif
47
48 #ifdef  TIME_WITH_SYS_TIME
49 #       ifndef  _INCL_SYS_TIME_H
50 #       include <sys/time.h>
51 #       define  _INCL_SYS_TIME_H
52 #       endif
53 #       ifndef  _INCL_TIME_H
54 #       include <time.h>
55 #       define  _INCL_TIME_H
56 #       endif
57 #else
58 #ifdef  HAVE_SYS_TIME_H
59 #       ifndef  _INCL_SYS_TIME_H
60 #       include <sys/time.h>
61 #       define  _INCL_SYS_TIME_H
62 #       endif
63 #else
64 #       ifndef  _INCL_TIME_H
65 #       include <time.h>
66 #       define  _INCL_TIME_H
67 #       endif
68 #endif
69 #endif
70
71 #ifdef  __cplusplus
72 extern "C" {
73 #endif
74
75 #if     defined(__CYGWIN32__) || defined(__EMX__) || defined(__linux__) || defined(__DJGPP__)
76 /*
77  * Cygnus defines struct timeval in sys/time.h but not timerclear
78  * timerclear is defined in windows32/Sockets.h ???
79  *
80  * EMX for OS/2 defines struct timeval in sys/time.h but not timerclear
81  *
82  * Linux defines struct timeval in sys/time.h but if __USE_BSD is not
83  * defined, timerclear is missing.
84  */
85 #ifndef timerclear
86 #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
87 #endif
88 #endif
89
90 #ifndef timerclear
91
92 #ifndef VMS
93 struct timeval {
94         long    tv_sec;
95         long    tv_usec;
96 };
97 #endif
98
99 struct timezone {
100         int     tz_minuteswest;
101         int     tz_dsttime;
102 };
103
104 #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
105
106 #endif
107
108 #undef  timerfix
109 #define timerfix1(tvp)          while ((tvp)->tv_usec < 0) {            \
110                                         (tvp)->tv_sec--;                \
111                                         (tvp)->tv_usec += 1000000;      \
112                                 }
113
114 #define timerfix2(tvp)          while ((tvp)->tv_usec > 1000000) {      \
115                                         (tvp)->tv_sec++;                \
116                                         (tvp)->tv_usec -= 1000000;      \
117                                 }
118
119 #define timerfix(tvp)           do { timerfix1(tvp); timerfix2(tvp); } while (0)
120
121 /*
122  * timersub() and timeradd() are defined on FreeBSD with a different
123  * interface (3 parameters).
124  */
125 #undef  timersub
126 #define timersub(tvp1, tvp2)    do {                                    \
127                                         (tvp1)->tv_sec -= (tvp2)->tv_sec; \
128                                         (tvp1)->tv_usec -= (tvp2)->tv_usec; \
129                                         timerfix1(tvp1); timerfix2(tvp1); \
130                                 } while (0)
131
132 #undef  timeradd
133 #define timeradd(tvp1, tvp2)    do {                                    \
134                                         (tvp1)->tv_sec += (tvp2)->tv_sec; \
135                                         (tvp1)->tv_usec += (tvp2)->tv_usec; \
136                                         timerfix1(tvp1); timerfix2(tvp1); \
137                                 } while (0)
138
139 #ifdef  __cplusplus
140 }
141 #endif
142
143 #endif  /* _TIMEDEFS_H */