BRL-CAD
time64.h
Go to the documentation of this file.
1 #ifndef TIME64_H
2 # define TIME64_H
3 
4 #include "common.h"
5 
6 #ifndef Y2038_EXPORT
7 # if defined(Y2038_DLL_EXPORTS) && defined(Y2038_DLL_IMPORTS)
8 # error "Only Y2038_DLL_EXPORTS or Y2038_DLL_IMPORTS can be defined, not both."
9 # elif defined(Y2038_DLL_EXPORTS)
10 # define Y2038_EXPORT __declspec(dllexport)
11 # elif defined(Y2038_DLL_IMPORTS)
12 # define Y2038_EXPORT __declspec(dllimport)
13 # else
14 # define Y2038_EXPORT
15 # endif
16 #endif
17 
18 #include <time.h>
19 #include "time64_config.h"
20 
21 
22 
23 /* Set our custom types */
25 typedef INT_64_T Year;
26 
27 /* A copy of the tm struct but with a 64 bit year */
28 struct TM64 {
29  int tm_sec;
30  int tm_min;
31  int tm_hour;
32  int tm_mday;
33  int tm_mon;
35  int tm_wday;
36  int tm_yday;
37  int tm_isdst;
38 
39 #ifdef HAS_TM_TM_GMTOFF
40  long tm_gmtoff;
41 #endif
42 
43 #ifdef HAS_TM_TM_ZONE
44  char *tm_zone;
45 #endif
46 };
47 
48 /* Decide which tm struct to use */
49 #ifdef USE_TM64
50 #define TM TM64
51 #else
52 #define TM tm
53 #endif
54 
55 /* Declare public functions */
56 Y2038_EXPORT struct TM *gmtime64_r (const Time64_T *, struct TM *);
57 Y2038_EXPORT struct TM *localtime64_r (const Time64_T *, struct TM *);
58 Y2038_EXPORT struct TM *gmtime64 (const Time64_T *);
59 Y2038_EXPORT struct TM *localtime64 (const Time64_T *);
60 
61 Y2038_EXPORT char *asctime64 (const struct TM *);
62 Y2038_EXPORT char *asctime64_r (const struct TM *, char *);
63 
64 Y2038_EXPORT char *ctime64 (const Time64_T*);
65 Y2038_EXPORT char *ctime64_r (const Time64_T*, char*);
66 
67 Y2038_EXPORT Time64_T timegm64 (const struct TM *);
68 Y2038_EXPORT Time64_T mktime64 (struct TM *);
70 
71 
72 /* Not everyone has gm/localtime_r(), provide a replacement */
73 #ifdef HAS_LOCALTIME_R
74 # define LOCALTIME_R(clock, result) localtime_r(clock, result)
75 #else
76 # define LOCALTIME_R(clock, result) fake_localtime_r(clock, result)
77 #endif
78 #ifdef HAS_GMTIME_R
79 # define GMTIME_R(clock, result) gmtime_r(clock, result)
80 #else
81 # define GMTIME_R(clock, result) fake_gmtime_r(clock, result)
82 #endif
83 
84 
85 /* Use a different asctime format depending on how big the year is */
86 #ifdef USE_TM64
87  #define TM64_ASCTIME_FORMAT "%.3s %.3s%3d %.2d:%.2d:%.2d %lld\n"
88 #else
89  #define TM64_ASCTIME_FORMAT "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"
90 #endif
91 
92 
93 #endif
INT_64_T Year
Definition: time64.h:25
int tm_isdst
Definition: time64.h:37
int tm_hour
Definition: time64.h:31
Y2038_EXPORT Time64_T timegm64(const struct TM *)
Definition: time64.c:279
Y2038_EXPORT char * asctime64_r(const struct TM *, char *)
Definition: time64.c:846
Year tm_year
Definition: time64.h:34
int tm_wday
Definition: time64.h:35
Y2038_EXPORT struct TM * localtime64_r(const Time64_T *, struct TM *)
Definition: time64.c:741
Header file for the BRL-CAD common definitions.
Y2038_EXPORT struct TM * localtime64(const Time64_T *)
Definition: time64.c:873
Y2038_EXPORT Time64_T timelocal64(struct TM *)
Definition: time64.c:609
Y2038_EXPORT char * ctime64(const Time64_T *)
Definition: time64.c:886
Y2038_EXPORT struct TM * gmtime64_r(const Time64_T *, struct TM *)
Definition: time64.c:614
int tm_sec
Definition: time64.h:29
int tm_min
Definition: time64.h:30
int tm_yday
Definition: time64.h:36
INT_64_T Time64_T
Definition: time64.h:24
int tm_mday
Definition: time64.h:32
Y2038_EXPORT Time64_T mktime64(struct TM *)
Definition: time64.c:568
Definition: time64.h:28
int tm_mon
Definition: time64.h:33
Y2038_EXPORT char * asctime64(const struct TM *)
Definition: time64.c:882
Y2038_EXPORT char * ctime64_r(const Time64_T *, char *)
Definition: time64.c:863
#define Y2038_EXPORT
Definition: time64.h:14
Y2038_EXPORT struct TM * gmtime64(const Time64_T *)
Definition: time64.c:878
#define TM
Definition: time64.h:52
#define INT_64_T
Definition: time64_config.h:24