source: trunk/server/lib/util/time.h@ 421

Last change on this file since 421 was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 6.2 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 time utility functions
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef _SAMBA_TIME_H_
20#define _SAMBA_TIME_H_
21
22#ifndef _PUBLIC_
23#define _PUBLIC_
24#endif
25
26/* 64 bit time (100 nanosec) 1601 - cifs6.txt, section 3.5, page 30, 4 byte aligned */
27typedef uint64_t NTTIME;
28
29/**
30 External access to time_t_min and time_t_max.
31**/
32_PUBLIC_ time_t get_time_t_max(void);
33
34/**
35a gettimeofday wrapper
36**/
37_PUBLIC_ void GetTimeOfDay(struct timeval *tval);
38
39/**
40interpret an 8 byte "filetime" structure to a time_t
41It's originally in "100ns units since jan 1st 1601"
42**/
43_PUBLIC_ time_t nt_time_to_unix(NTTIME nt);
44
45/**
46put a 8 byte filetime from a time_t
47This takes GMT as input
48**/
49_PUBLIC_ void unix_to_nt_time(NTTIME *nt, time_t t);
50
51/**
52check if it's a null unix time
53**/
54_PUBLIC_ bool null_time(time_t t);
55
56/**
57check if it's a null NTTIME
58**/
59_PUBLIC_ bool null_nttime(NTTIME t);
60
61/**
62put a dos date into a buffer (time/date format)
63This takes GMT time and puts local time in the buffer
64**/
65_PUBLIC_ void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset);
66
67/**
68put a dos date into a buffer (date/time format)
69This takes GMT time and puts local time in the buffer
70**/
71_PUBLIC_ void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset);
72
73/**
74put a dos 32 bit "unix like" date into a buffer. This routine takes
75GMT and converts it to LOCAL time before putting it (most SMBs assume
76localtime for this sort of date)
77**/
78_PUBLIC_ void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset);
79
80/**
81 create a unix date (int GMT) from a dos date (which is actually in
82 localtime)
83**/
84_PUBLIC_ time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset);
85
86/**
87like make_unix_date() but the words are reversed
88**/
89_PUBLIC_ time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset);
90
91/**
92 create a unix GMT date from a dos date in 32 bit "unix like" format
93 these generally arrive as localtimes, with corresponding DST
94**/
95_PUBLIC_ time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset);
96
97/**
98return a HTTP/1.0 time string
99**/
100_PUBLIC_ char *http_timestring(TALLOC_CTX *mem_ctx, time_t t);
101
102/**
103 Return the date and time as a string
104**/
105_PUBLIC_ char *timestring(TALLOC_CTX *mem_ctx, time_t t);
106
107/**
108 return a talloced string representing a NTTIME for human consumption
109*/
110_PUBLIC_ const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt);
111
112/**
113 put a NTTIME into a packet
114*/
115_PUBLIC_ void push_nttime(uint8_t *base, uint16_t offset, NTTIME t);
116
117/**
118 pull a NTTIME from a packet
119*/
120_PUBLIC_ NTTIME pull_nttime(uint8_t *base, uint16_t offset);
121
122/**
123 parse a nttime as a large integer in a string and return a NTTIME
124*/
125_PUBLIC_ NTTIME nttime_from_string(const char *s);
126
127/**
128 return (tv1 - tv2) in microseconds
129*/
130_PUBLIC_ int64_t usec_time_diff(const struct timeval *tv1, const struct timeval *tv2);
131
132/**
133 return a zero timeval
134*/
135_PUBLIC_ struct timeval timeval_zero(void);
136
137/**
138 return true if a timeval is zero
139*/
140_PUBLIC_ bool timeval_is_zero(const struct timeval *tv);
141
142/**
143 return a timeval for the current time
144*/
145_PUBLIC_ struct timeval timeval_current(void);
146
147/**
148 return a timeval struct with the given elements
149*/
150_PUBLIC_ struct timeval timeval_set(uint32_t secs, uint32_t usecs);
151
152/**
153 return a timeval ofs microseconds after tv
154*/
155_PUBLIC_ struct timeval timeval_add(const struct timeval *tv,
156 uint32_t secs, uint32_t usecs);
157
158/**
159 return the sum of two timeval structures
160*/
161struct timeval timeval_sum(const struct timeval *tv1,
162 const struct timeval *tv2);
163
164/**
165 return a timeval secs/usecs into the future
166*/
167_PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs);
168
169/**
170 compare two timeval structures.
171 Return -1 if tv1 < tv2
172 Return 0 if tv1 == tv2
173 Return 1 if tv1 > tv2
174*/
175_PUBLIC_ int timeval_compare(const struct timeval *tv1, const struct timeval *tv2);
176
177/**
178 return true if a timer is in the past
179*/
180_PUBLIC_ bool timeval_expired(const struct timeval *tv);
181
182/**
183 return the number of seconds elapsed between two times
184*/
185_PUBLIC_ double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2);
186
187/**
188 return the number of seconds elapsed since a given time
189*/
190_PUBLIC_ double timeval_elapsed(const struct timeval *tv);
191
192/**
193 return the lesser of two timevals
194*/
195_PUBLIC_ struct timeval timeval_min(const struct timeval *tv1,
196 const struct timeval *tv2);
197
198/**
199 return the greater of two timevals
200*/
201_PUBLIC_ struct timeval timeval_max(const struct timeval *tv1,
202 const struct timeval *tv2);
203
204/**
205 return the difference between two timevals as a timeval
206 if tv1 comes after tv2, then return a zero timeval
207 (this is *tv2 - *tv1)
208*/
209_PUBLIC_ struct timeval timeval_until(const struct timeval *tv1,
210 const struct timeval *tv2);
211
212/**
213 convert a timeval to a NTTIME
214*/
215_PUBLIC_ NTTIME timeval_to_nttime(const struct timeval *tv);
216
217/**
218 convert a NTTIME to a timeval
219*/
220_PUBLIC_ void nttime_to_timeval(struct timeval *tv, NTTIME t);
221
222/**
223 return the UTC offset in seconds west of UTC, or 0 if it cannot be determined
224 */
225_PUBLIC_ int get_time_zone(time_t t);
226
227/**
228 check if 2 NTTIMEs are equal.
229*/
230bool nt_time_equal(NTTIME *t1, NTTIME *t2);
231
232void interpret_dos_date(uint32_t date,int *year,int *month,int *day,int *hour,int *minute,int *second);
233
234struct timespec nt_time_to_unix_timespec(NTTIME *nt);
235
236time_t convert_timespec_to_time_t(struct timespec ts);
237
238struct timespec convert_time_t_to_timespec(time_t t);
239
240bool null_timespec(struct timespec ts);
241
242/** Extra minutes to add to the normal GMT to local time conversion. */
243extern int extra_time_offset;
244
245#endif /* _SAMBA_TIME_H_ */
Note: See TracBrowser for help on using the repository browser.