]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/sys/time.h
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / StdLib / Include / sys / time.h
CommitLineData
2aa62f2b 1/** @file\r
2 System-specific declarations and macros related to time.\r
3\r
53e1e5c6 4 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
2aa62f2b 5 This program and the accompanying materials are licensed and made available under\r
6 the terms and conditions of the BSD License that accompanies this distribution.\r
7 The full text of the license may be found at\r
53e1e5c6 8 http://opensource.org/licenses/bsd-license.\r
2aa62f2b 9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13 Copyright (c) 1982, 1986, 1993\r
14 The Regents of the University of California. All rights reserved.\r
15\r
16 Redistribution and use in source and binary forms, with or without\r
17 modification, are permitted provided that the following conditions\r
18 are met:\r
19 1. Redistributions of source code must retain the above copyright\r
20 notice, this list of conditions and the following disclaimer.\r
21 2. Redistributions in binary form must reproduce the above copyright\r
22 notice, this list of conditions and the following disclaimer in the\r
23 documentation and/or other materials provided with the distribution.\r
24 3. Neither the name of the University nor the names of its contributors\r
25 may be used to endorse or promote products derived from this software\r
26 without specific prior written permission.\r
27\r
28 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
29 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
30 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
31 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
32 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
33 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
34 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
35 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
36 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
37 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
38 SUCH DAMAGE.\r
39\r
40 time.h 8.5 (Berkeley) 5/4/95\r
41 NetBSD: time.h,v 1.56 2006/06/18 21:09:24 uwe Exp\r
42 */\r
43#ifndef _SYS_TIME_H_\r
44#define _SYS_TIME_H_\r
45\r
46#include <Uefi.h>\r
47#include <sys/featuretest.h>\r
48#include <sys/types.h>\r
49\r
50/*\r
51 * Traditional *nix structure returned by gettimeofday(2) system call,\r
52 * and used in other calls.\r
53 */\r
54struct timeval {\r
55 LONG32 tv_sec; /* seconds */\r
56 LONG32 tv_usec; /* and microseconds */\r
57};\r
58\r
59/*\r
60 * Structure defined by POSIX.1b to be like a timeval.\r
61 * This works within EFI since the times really are time_t.\r
2aa62f2b 62 */\r
63struct timespec {\r
64 time_t tv_sec; /* seconds */\r
0c1992fb 65 LONG32 tv_nsec; /* and nanoseconds */\r
2aa62f2b 66};\r
67\r
68#define TIMEVAL_TO_TIMESPEC(tv, ts) do { \\r
69 (ts)->tv_sec = (tv)->tv_sec; \\r
70 (ts)->tv_nsec = (tv)->tv_usec * 1000; \\r
71} while (/*CONSTCOND*/0)\r
d7ce7006 72\r
2aa62f2b 73#define TIMESPEC_TO_TIMEVAL(tv, ts) do { \\r
74 (tv)->tv_sec = (ts)->tv_sec; \\r
75 (tv)->tv_usec = (ts)->tv_nsec / 1000; \\r
76} while (/*CONSTCOND*/0)\r
77\r
78/* Operations on timevals. */\r
79#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0\r
80#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)\r
d7ce7006 81\r
2aa62f2b 82#define timercmp(tvp, uvp, cmp) \\r
83 (((tvp)->tv_sec == (uvp)->tv_sec) ? \\r
84 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \\r
85 ((tvp)->tv_sec cmp (uvp)->tv_sec))\r
d7ce7006 86\r
2aa62f2b 87#define timeradd(tvp, uvp, vvp) \\r
88 do { \\r
89 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \\r
90 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \\r
91 if ((vvp)->tv_usec >= 1000000) { \\r
92 (vvp)->tv_sec++; \\r
93 (vvp)->tv_usec -= 1000000; \\r
94 } \\r
95 } while (/* CONSTCOND */ 0)\r
d7ce7006 96\r
2aa62f2b 97#define timersub(tvp, uvp, vvp) \\r
98 do { \\r
99 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \\r
100 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \\r
101 if ((vvp)->tv_usec < 0) { \\r
102 (vvp)->tv_sec--; \\r
103 (vvp)->tv_usec += 1000000; \\r
104 } \\r
105 } while (/* CONSTCOND */ 0)\r
106\r
107/* Operations on timespecs. */\r
108#define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0\r
109#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)\r
d7ce7006 110\r
2aa62f2b 111#define timespeccmp(tsp, usp, cmp) \\r
112 (((tsp)->tv_sec == (usp)->tv_sec) ? \\r
113 ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \\r
114 ((tsp)->tv_sec cmp (usp)->tv_sec))\r
d7ce7006 115\r
2aa62f2b 116#define timespecadd(tsp, usp, vsp) \\r
117 do { \\r
118 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \\r
119 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \\r
120 if ((vsp)->tv_nsec >= 1000000000L) { \\r
121 (vsp)->tv_sec++; \\r
122 (vsp)->tv_nsec -= 1000000000L; \\r
123 } \\r
124 } while (/* CONSTCOND */ 0)\r
d7ce7006 125\r
2aa62f2b 126#define timespecsub(tsp, usp, vsp) \\r
127 do { \\r
128 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \\r
129 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \\r
130 if ((vsp)->tv_nsec < 0) { \\r
131 (vsp)->tv_sec--; \\r
132 (vsp)->tv_nsec += 1000000000L; \\r
133 } \\r
134 } while (/* CONSTCOND */ 0)\r
135\r
136/*\r
137 * Names of the interval timers, and structure\r
138 * defining a timer setting.\r
139 */\r
140#define ITIMER_REAL 0\r
141#define ITIMER_VIRTUAL 1\r
142#define ITIMER_PROF 2\r
143\r
144struct itimerval {\r
145 struct timeval it_interval; /* timer interval */\r
146 struct timeval it_value; /* current value */\r
147};\r
148\r
149/*\r
150 * Structure defined by POSIX.1b to be like a itimerval, but with\r
151 * timespecs. Used in the timer_*() system calls.\r
152 */\r
153struct itimerspec {\r
154 struct timespec it_interval;\r
155 struct timespec it_value;\r
156};\r
157\r
158#define CLOCK_REALTIME 0\r
159#define CLOCK_VIRTUAL 1\r
160#define CLOCK_PROF 2\r
161#define CLOCK_MONOTONIC 3\r
162\r
163#define TIMER_RELTIME 0x0 /* relative timer */\r
164#define TIMER_ABSTIME 0x1 /* absolute timer */\r
165\r
166#if 0\r
167 #if (_POSIX_C_SOURCE - 0) >= 200112L || \\r
168 (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \\r
169 (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)\r
170 #include <sys/select.h>\r
171 #endif\r
172#endif /* if 0 */\r
173\r
174#include <sys/EfiCdefs.h>\r
175#include <time.h>\r
176\r
177/* Functions useful for dealing with EFI */\r
178__BEGIN_DECLS\r
179\r
180/* Convert an EFI_TIME structure into a time_t value. */\r
181time_t Efi2Time( EFI_TIME *EfiBDtime);\r
182\r
0c1992fb 183/* Convert a time_t value into an EFI_TIME structure.\r
184 It is the caller's responsibility to free the returned structure.\r
185*/\r
186EFI_TIME * Time2Efi(time_t OTime);\r
187\r
2aa62f2b 188/* Convert an EFI_TIME structure into a C Standard tm structure. */\r
189void Efi2Tm( EFI_TIME *EfiBDtime, struct tm *NewTime);\r
0c1992fb 190void Tm2Efi( struct tm *BdTime, EFI_TIME *ETime);\r
2aa62f2b 191\r
53e1e5c6 192/* BSD compatibility functions */\r
193int gettimeofday (struct timeval *tp, void *ignore);\r
d7ce7006 194/* POSIX compatibility functions */\r
195int getitimer (int which, struct itimerval *value);\r
196int setitimer (int which, const struct itimerval *value, struct itimerval *ovalue);\r
53e1e5c6 197\r
0c1992fb 198__END_DECLS\r
199\r
2aa62f2b 200#endif /* !_SYS_TIME_H_ */\r