Debian Codegraph @

contrib/time64.h

raw
1 /* Copyright (c) Robert Walker, [email protected]
2 * Free source. Do what you wish with it - treat it as you would
3 * example code in a book on c programming.
4 */
5
6 /* Note
7 * When you include this header then all your time_t variables will become
8 * __int64 variables.
9 *
10 * Be sure to check that routines that use them work with __int64 variables.
11 * By way of example, if you use sprintf, fprintf, sscanf, fscanf etc
12 * then you won't be able to use the %d format field for these variables
13 * in a 32 bit build - they will overflow and be used for the next format field
14 * as well. Instead convert your variables to unsigned ints and use %lu
15 *
16 * e.g.
17 * sprintf(sz,"time_saved %lu secs",(UINT)time(NULL));
18 *
19 * {
20 * time_t time_saved=0;
21 * UINT utime_saved=0;
22 * sscanf( sz, "%*s%lu", &utime_saved);
23 * // read it in as an unsigned long as sscanf can't read to __int64 variables
24 * // directly
25 * time_saved=utime_saved;
26 * }
27 *
28
29 * Unsigned ints are fine for dates until beyond the end of this century
30 *
31 * If your compiler has some other type of native 64 bit type then
32 * change the line typedef __int64 t64
33 */
34
35 #include <time.h>
36
37 #include "regina64.h"
38
39 /*
40 * Note. I think the usual time functions aren't thread safe becuase they use
41 * a single struct for localtime, gmtime and mktime. Several threads
42 * might access that same structure simultaneously.
43 *
44 * However we can make this implementation thread safe using thread local
45 * variables if we so wish - simply define the tm struct that they
46 * return to be thread local. But - I'm not sure if the pointer you get
47 * back from localtime can be kept for any length of time with thread
48 * local variables. Can the address for it change?? Anyone know?
49 *
50 * You can't use this method with DLLs that might be loaded using LoadLibrary
51 * - see
52 * http://msdn.microsoft.com/library/en-us/dllproc/base/dynamic_link_library_data.asp
53 */
54
55 // #define USE_THREAD_LOCAL_VARIABLES
56
57 #undef time
58 #undef localtime
59 #undef mktime
60 #undef difftime
61 #undef gmtime
62
63 /*
64 #define time time_64
65 */
66 #define localtime localtime_64
67 #define mktime mktime_64
68 #define difftime difftime_64
69 #define gmtime gmtime_64
70
71 typedef rx_64 t64;
72 #define time_t t64
73 t64 time_64(t64 *pt);
74 struct tm *localtime_64(t64 *pt);
75 double difftime_64(t64 time1, t64 time0);
76 t64 mktime_64( struct tm *today );
77 struct tm *gmtime_64(t64 *t);
78
79 /* allow multiple inclusion of this file - does no harm, and we want
80 * the last one to be effective if included several times
81 * as in
82 * #include "time64.h"
83 * ...
84 * #include <time.h>
85 * ...
86 * #include "time64.h"
87 */