1 #ifndef UNIX_TIME_WIN_PATCH_H
2 #define UNIX_TIME_WIN_PATCH_H
3 
4 #include "config.h"
5 
6 #include <sys/cdefs.h>
7 
8 #include <time.h>
9 #include <ctype.h>
10 #include <errno.h>
11 #include <locale.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <pthread.h>
15 
16 #if defined(_WIN32)
17 #include <Windows.h>
18 #endif
19 
20 #if !defined(TM_YEAR_BASE)
21 #define TM_YEAR_BASE 1900
22 #endif
23 
24 #if !defined(TM_SUNDAY)
25 #define TM_SUNDAY   0
26 #endif
27 
28 #if !defined(TM_MONDAY)
29 #define TM_MONDAY   1
30 #endif
31 
32 #if !defined(DAYSPERLYEAR)
33 #define DAYSPERLYEAR    366
34 #endif
35 
36 #if !defined(SECSPERMIN)
37 #define SECSPERMIN  60
38 #endif
39 
40 #if !defined(MINSPERHOUR)
41 #define MINSPERHOUR 60
42 #endif
43 
44 #if !defined(HOURSPERDAY)
45 #define HOURSPERDAY 24
46 #endif
47 
48 #if !defined(TM_YEAR_BASE)
49 #define TM_YEAR_BASE    1900
50 #endif
51 
52 #if !defined(MONSPERYEAR)
53 #define MONSPERYEAR 12
54 #endif
55 
56 #if !defined(DAYSPERWEEK)
57 #define DAYSPERWEEK 7
58 #endif
59 
60 #if !defined(DAYSPERNYEAR)
61 #define DAYSPERNYEAR    365
62 #endif
63 
64 #ifndef TYPE_BIT
65 #define TYPE_BIT(type)  (sizeof (type) * CHAR_BIT)
66 #endif /* !defined TYPE_BIT */
67 
68 #ifndef TYPE_SIGNED
69 #define TYPE_SIGNED(type) (((type) -1) < 0)
70 #endif /* !defined TYPE_SIGNED */
71 
72 #ifndef INT_STRLEN_MAXIMUM
73 /*
74 ** 302 / 1000 is log10(2.0) rounded up.
75 ** Subtract one for the sign bit if the type is signed;
76 ** add one for integer division truncation;
77 ** add one more for a minus sign if the type is signed.
78 */
79 #define INT_STRLEN_MAXIMUM(type) \
80     ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
81     1 + TYPE_SIGNED(type))
82 #endif /* !defined INT_STRLEN_MAXIMUM */
83 
84 #if HAVE__ISSPACE_L
85 #define isspace_l _isspace_l
86 #else
87 #define isspace_l(ch, locale) isspace(ch)
88 #endif
89 
90 #if HAVE__ISUPPER_L
91 #define isupper_l _isupper_l
92 #else
93 #define isupper_l(ch, locale) isupper(ch)
94 #endif
95 
96 #if HAVE__ISDIGIT_L
97 #define isdigit_l _isdigit_l
98 #else
99 #define isdigit_l(ch, locale) isdigit(ch)
100 #endif
101 
102 #if !HAVE_STRTOL_L
103 long strtol_l(const char *nptr, char **endptr, int base, _locale_t locale);
104 #endif
105 
106 #if !HAVE_STRTOLL_L
107 long long strtoll_l(const char *nptr, char **endptr, int base, _locale_t locale);
108 #endif
109 
110 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
111 
112 #ifndef isleap_sum
113 /*
114 ** See tzfile.h for details on isleap_sum.
115 */
116 #define isleap_sum(a, b)    isleap((a) % 400 + (b) % 400)
117 #endif /* !defined isleap_sum */
118 
119 #if !HAVE__ISBLANK_L
120 int isblank_l( int c, _locale_t _loc);
121 #endif
122 
123 int strncasecmp_l(const char *s1, const char *s2, int len, _locale_t _loc);
124 
125 struct tm *gmtime_r(const time_t *_time_t, struct tm *_tm);
126 
127 struct tm *localtime_r(const time_t *_time_t, struct tm *_tm);
128 
129 #if HAVE__MKGMTIME
130 #define timegm _mkgmtime
131 #define HAVE_TIMEGM 1
132 #endif
133 
134 #define fprintf_l(fp, loc, ...) fprintf(fp, ##__VA_ARGS__)
135 #define sprintf_l(buf, loc, ...) sprintf(buf, ##__VA_ARGS__)
136 
137 struct lc_time_T {
138     const char  *mon[12];
139     const char  *month[12];
140     const char  *wday[7];
141     const char  *weekday[7];
142     const char  *X_fmt;
143     const char  *x_fmt;
144     const char  *c_fmt;
145     const char  *am;
146     const char  *pm;
147     const char  *date_fmt;
148     const char  *alt_month[12];
149     const char  *md_order;
150     const char  *ampm_fmt;
151 };
152 
153 extern const struct lc_time_T   _C_time_locale;
154 
155 int _patch_setenv(const char *var, const char *val, int ovr);
156 
157 int _patch_unsetenv(const char *name);
158 
159 size_t _patch_strftime(char * __restrict s, size_t maxsize, const char * __restrict format,
160     const struct tm * __restrict t);
161 
162 size_t _patch_strftime_l(char * __restrict s, size_t maxsize, const char * __restrict format,
163     const struct tm * __restrict t, _locale_t loc);
164 
165 char *strptime_l(const char * __restrict buf, const char * __restrict fmt,
166     struct tm * __restrict tm, _locale_t loc);
167 
168 char *strptime(const char * __restrict buf, const char * __restrict fmt,
169     struct tm * __restrict tm);
170 
171 #endif // UNIX_TIME_WIN_PATCH_H
172