Repository navigation
Expand file tree
/
Copy pathconversion_functions.h
More file actions
383 lines (324 loc) · 9.22 KB
/
Copy pathconversion_functions.h
File metadata and controls
383 lines (324 loc) · 9.22 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/* /////////////////////////////////////////////////////////////////////////
* File: winstl/time/conversion_functions.h
*
* Purpose: Comparison functions for Windows time structures.
*
* Created: 21st November 2003
* Updated: 11th October 2026
*
* Home: http://stlsoft.org/
*
* Copyright (c) 2019-2026, Matthew Wilson and Synesis Information Systems
* Copyright (c) 2003-2019, Matthew Wilson and Synesis Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name(s) of Matthew Wilson and Synesis Information Systems
* nor the names of any contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ////////////////////////////////////////////////////////////////////// */
/** \file winstl/time/conversion_functions.h
*
* \brief [C, C++] Conversion functions for Windows time types
* (\ref group__library__Time "Time" Library).
*/
#ifndef WINSTL_INCL_WINSTL_TIME_H_CONVERSION_FUNCTIONS
#define WINSTL_INCL_WINSTL_TIME_H_CONVERSION_FUNCTIONS
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define WINSTL_VER_WINSTL_TIME_H_CONVERSION_FUNCTIONS_MAJOR 4
# define WINSTL_VER_WINSTL_TIME_H_CONVERSION_FUNCTIONS_MINOR 1
# define WINSTL_VER_WINSTL_TIME_H_CONVERSION_FUNCTIONS_REVISION 8
# define WINSTL_VER_WINSTL_TIME_H_CONVERSION_FUNCTIONS_EDIT 71
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* includes
*/
#ifndef WINSTL_INCL_WINSTL_H_WINSTL
# include <winstl/winstl.h>
#endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
#ifdef STLSOFT_TRACE_INCLUDE
# pragma message(__FILE__)
#endif /* STLSOFT_TRACE_INCLUDE */
#ifndef STLSOFT_INCL_H_TIME
# define STLSOFT_INCL_H_TIME
# include <time.h>
#endif /* !STLSOFT_INCL_H_TIME */
/* /////////////////////////////////////////////////////////////////////////
* namespace
*/
#if !defined(WINSTL_NO_NAMESPACE) && \
!defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
# if defined(STLSOFT_NO_NAMESPACE)
/* There is no stlsoft namespace, so must define ::winstl */
namespace winstl
{
# else
/* Define stlsoft::winstl_project */
namespace stlsoft
{
namespace winstl_project
{
# endif /* STLSOFT_NO_NAMESPACE */
#endif /* !WINSTL_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* C functions
*/
/** Converts a time_t into a FILETIME
*
* \ingroup group__library__Time
*
* \note This follows the algorithm provided in MSDN Q167296
*
* \pre nullptr != ft
*/
STLSOFT_INLINE
void
winstl_C_UNIXTimeToFILETIME(
time_t t
, FILETIME* ft
)
{
ws_uint64_t const i = UInt32x32To64(t, 10000000) + STLSOFT_GEN_UINT64_SUFFIX(116444736000000000);
WINSTL_ASSERT(NULL != ft);
ft->dwLowDateTime = (DWORD)i;
ft->dwHighDateTime = (DWORD)(i >> 32);
}
/** Converts a time_t and a microseconds value into a FILETIME
*
* \ingroup group__library__Time
*
* \note This follows the algorithm provided in MSDN Q167296
*
* \pre nullptr != ft
*/
STLSOFT_INLINE
void
winstl_C_UNIXTimeToFILETIME_us(
time_t t
, ws_sint32_t usec
, FILETIME* ft
)
{
ws_uint64_t const i = UInt32x32To64(t, 10000000) + Int32x32To64(usec, 10) + STLSOFT_GEN_UINT64_SUFFIX(116444736000000000);
WINSTL_ASSERT(NULL != ft);
ft->dwLowDateTime = (DWORD)i;
ft->dwHighDateTime = (DWORD)(i >> 32);
}
/** Converts a FILETIME into a time_t
*
* \ingroup group__library__Time
*
* \note This follows the algorithm provided in MSDN Q167296
*
* \pre nullptr != ft
*/
STLSOFT_INLINE
time_t
winstl_C_FILETIMEToUNIXTime(
FILETIME const* ft
, ws_sint32_t* microseconds
)
{
ws_sint64_t i;
WINSTL_ASSERT(NULL != ft);
i = ft->dwHighDateTime;
i <<= 32;
i |= ft->dwLowDateTime;
i -= STLSOFT_GEN_UINT64_SUFFIX(116444736000000000);
if (NULL != microseconds)
{
*microseconds = stlsoft_static_cast(ws_sint32_t, (i % 10000000) / 10);
WINSTL_ASSERT(*microseconds >= 0 && *microseconds <= 999999);
}
i /= 10000000;
return stlsoft_static_cast(time_t, i);
}
/* /////////////////////////////////////////////////////////////////////////
* obsolete symbols
*
* NOTE: these are only defined if:
*
* - we're generating documentation, or
* - STLSOFT_OBSOLETE is specified, or
* - it's STLSoft 1.9 (or earlier)
*/
#if defined(STLSOFT_DOCUMENTATION_SKIP_SECTION) || \
defined(STLSOFT_OBSOLETE) || \
_STLSOFT_VER < 0x010a0000
/** \def winstl__UNIXTimeToFILETIME
*
* \deprecated Use winstl_C_UNIXTimeToFILETIME
*/
# define winstl__UNIXTimeToFILETIME winstl_C_UNIXTimeToFILETIME
/** \def winstl__UNIXTimeToFILETIME_us
*
* \deprecated Use winstl_C_UNIXTimeToFILETIME_us
*/
# define winstl__UNIXTimeToFILETIME_us winstl_C_UNIXTimeToFILETIME_us
/** \def winstl__FILETIMEToUNIXTime
*
* \deprecated Use winstl_C_FILETIMEToUNIXTime
*/
# define winstl__FILETIMEToUNIXTime winstl_C_FILETIMEToUNIXTime
#endif /* obsolete || 1.9 */
/* /////////////////////////////////////////////////////////////////////////
* namespace
*/
#ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
namespace winstl
{
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* C++ functions
*/
#ifdef __cplusplus
# ifdef STLSOFT_CF_64BIT_INT_SUPPORT
/** Converts a time_t into a FILETIME
*
* \ingroup group__library__Time
*
* \note This follows the algorithm provided in MSDN Q167296
*/
inline
void
UNIXTimeToFILETIME(
time_t t
, FILETIME& ft
)
{
winstl_C_UNIXTimeToFILETIME(t, &ft);
}
/** Converts a time_t into a FILETIME
*
* \ingroup group__library__Time
*
* \note This follows the algorithm provided in MSDN Q167296
*/
inline
FILETIME
UNIXTimeToFILETIME(
time_t t
)
{
FILETIME ft;
winstl_C_UNIXTimeToFILETIME(t, &ft);
return ft;
}
/** Converts a time_t + microseconds into a FILETIME
*
* \ingroup group__library__Time
*
* \note This follows the algorithm provided in MSDN Q167296
*/
inline
void
UNIXTimeToFILETIME(
time_t t
, ws_sint32_t usec
, FILETIME& ft
)
{
winstl_C_UNIXTimeToFILETIME_us(t, usec, &ft);
}
/** Converts a time_t + microseconds into a FILETIME
*
* \ingroup group__library__Time
*
* \note This follows the algorithm provided in MSDN Q167296
*/
inline
FILETIME
UNIXTimeToFILETIME(
time_t t
, ws_sint32_t usec
)
{
FILETIME ft;
winstl_C_UNIXTimeToFILETIME_us(t, usec, &ft);
return ft;
}
/** Converts a FILETIME into a time_t
*
* \ingroup group__library__Time
*/
inline
time_t
FILETIMEToUNIXTime(
FILETIME const& ft
, ws_sint32_t* microseconds = NULL
)
{
return winstl_C_FILETIMEToUNIXTime(&ft, microseconds);
}
/** Converts a FILETIME into a time_t
*
* \ingroup group__library__Time
*/
inline
void
FILETIMEToUNIXTime(
FILETIME const& ft
, time_t& t
)
{
t = winstl_C_FILETIMEToUNIXTime(&ft, NULL);
}
/** Converts a FILETIME into a time_t
*
* \ingroup group__library__Time
*/
inline
void
FILETIMEToUNIXTime(
FILETIME const& ft
, time_t& t
, ws_sint32_t& microseconds
)
{
t = winstl_C_FILETIMEToUNIXTime(&ft, µseconds);
}
# endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
#endif /* __cplusplus */
/* /////////////////////////////////////////////////////////////////////////
* namespace
*/
#ifndef WINSTL_NO_NAMESPACE
# if defined(STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} /* namespace winstl */
# else
} /* namespace winstl_project */
} /* namespace stlsoft */
# endif /* STLSOFT_NO_NAMESPACE */
#endif /* !WINSTL_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* inclusion control
*/
#ifdef STLSOFT_CF_PRAGMA_ONCE_SUPPORT
# pragma once
#endif /* STLSOFT_CF_PRAGMA_ONCE_SUPPORT */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* !WINSTL_INCL_WINSTL_TIME_H_CONVERSION_FUNCTIONS */
/* ///////////////////////////// end of file //////////////////////////// */