|
41 | 41 | //include valgrind.h after stdint.h so that uintptr_t is defined for msys2 w64 |
42 | 42 | #include "valgrind/valgrind.h" |
43 | 43 |
|
44 | | -#ifdef __ANDROID__ |
45 | | -time_t |
46 | | -timegm(struct tm *tm) |
47 | | -{ |
48 | | - time_t ret; |
49 | | - char *tz; |
50 | | - |
51 | | - tz = getenv("TZ"); |
52 | | - if (tz) |
53 | | - tz = strdup(tz); |
54 | | - setenv("TZ", "", 1); |
55 | | - tzset(); |
56 | | - ret = mktime(tm); |
57 | | - if (tz) { |
58 | | - setenv("TZ", tz, 1); |
59 | | - free(tz); |
60 | | - } else |
61 | | - unsetenv("TZ"); |
62 | | - tzset(); |
63 | | - return ret; |
64 | | -} |
65 | | -#endif |
66 | | - |
67 | 44 | #ifdef __APPLE__ |
68 | 45 | #if (TARGET_OS_IPHONE) |
69 | 46 | extern char **environ; |
@@ -100,121 +77,6 @@ rust_list_dir_val(struct dirent* entry_ptr) { |
100 | 77 | } |
101 | 78 | #endif |
102 | 79 |
|
103 | | -typedef struct { |
104 | | - int32_t tm_sec; |
105 | | - int32_t tm_min; |
106 | | - int32_t tm_hour; |
107 | | - int32_t tm_mday; |
108 | | - int32_t tm_mon; |
109 | | - int32_t tm_year; |
110 | | - int32_t tm_wday; |
111 | | - int32_t tm_yday; |
112 | | - int32_t tm_isdst; |
113 | | - int32_t tm_gmtoff; |
114 | | - int32_t tm_nsec; |
115 | | -} rust_tm; |
116 | | - |
117 | | -void rust_tm_to_tm(rust_tm* in_tm, struct tm* out_tm) { |
118 | | - memset(out_tm, 0, sizeof(struct tm)); |
119 | | - out_tm->tm_sec = in_tm->tm_sec; |
120 | | - out_tm->tm_min = in_tm->tm_min; |
121 | | - out_tm->tm_hour = in_tm->tm_hour; |
122 | | - out_tm->tm_mday = in_tm->tm_mday; |
123 | | - out_tm->tm_mon = in_tm->tm_mon; |
124 | | - out_tm->tm_year = in_tm->tm_year; |
125 | | - out_tm->tm_wday = in_tm->tm_wday; |
126 | | - out_tm->tm_yday = in_tm->tm_yday; |
127 | | - out_tm->tm_isdst = in_tm->tm_isdst; |
128 | | -} |
129 | | - |
130 | | -void tm_to_rust_tm(struct tm* in_tm, |
131 | | - rust_tm* out_tm, |
132 | | - int32_t gmtoff, |
133 | | - int32_t nsec) { |
134 | | - out_tm->tm_sec = in_tm->tm_sec; |
135 | | - out_tm->tm_min = in_tm->tm_min; |
136 | | - out_tm->tm_hour = in_tm->tm_hour; |
137 | | - out_tm->tm_mday = in_tm->tm_mday; |
138 | | - out_tm->tm_mon = in_tm->tm_mon; |
139 | | - out_tm->tm_year = in_tm->tm_year; |
140 | | - out_tm->tm_wday = in_tm->tm_wday; |
141 | | - out_tm->tm_yday = in_tm->tm_yday; |
142 | | - out_tm->tm_isdst = in_tm->tm_isdst; |
143 | | - out_tm->tm_gmtoff = gmtoff; |
144 | | - out_tm->tm_nsec = nsec; |
145 | | -} |
146 | | - |
147 | | -#if defined(__WIN32__) |
148 | | -#define TZSET() _tzset() |
149 | | -#if defined(_MSC_VER) && (_MSC_VER >= 1400) |
150 | | -#define GMTIME(clock, result) gmtime_s((result), (clock)) |
151 | | -#define LOCALTIME(clock, result) localtime_s((result), (clock)) |
152 | | -#define TIMEGM(result) _mkgmtime64(result) |
153 | | -#else |
154 | | -struct tm* GMTIME(const time_t *clock, struct tm *result) { |
155 | | - struct tm* t = gmtime(clock); |
156 | | - if (t == NULL || result == NULL) { return NULL; } |
157 | | - *result = *t; |
158 | | - return result; |
159 | | -} |
160 | | -struct tm* LOCALTIME(const time_t *clock, struct tm *result) { |
161 | | - struct tm* t = localtime(clock); |
162 | | - if (t == NULL || result == NULL) { return NULL; } |
163 | | - *result = *t; |
164 | | - return result; |
165 | | -} |
166 | | -#define TIMEGM(result) mktime((result)) - _timezone |
167 | | -#endif |
168 | | -#else |
169 | | -#define TZSET() tzset() |
170 | | -#define GMTIME(clock, result) gmtime_r((clock), (result)) |
171 | | -#define LOCALTIME(clock, result) localtime_r((clock), (result)) |
172 | | -#define TIMEGM(result) timegm(result) |
173 | | -#endif |
174 | | - |
175 | | -void |
176 | | -rust_tzset() { |
177 | | - TZSET(); |
178 | | -} |
179 | | - |
180 | | -void |
181 | | -rust_gmtime(int64_t sec, int32_t nsec, rust_tm *timeptr) { |
182 | | - struct tm tm; |
183 | | - time_t s = sec; |
184 | | - GMTIME(&s, &tm); |
185 | | - |
186 | | - tm_to_rust_tm(&tm, timeptr, 0, nsec); |
187 | | -} |
188 | | - |
189 | | -void |
190 | | -rust_localtime(int64_t sec, int32_t nsec, rust_tm *timeptr) { |
191 | | - struct tm tm; |
192 | | - time_t s = sec; |
193 | | - LOCALTIME(&s, &tm); |
194 | | - |
195 | | -#if defined(__WIN32__) |
196 | | - int32_t gmtoff = -timezone; |
197 | | -#else |
198 | | - int32_t gmtoff = tm.tm_gmtoff; |
199 | | -#endif |
200 | | - |
201 | | - tm_to_rust_tm(&tm, timeptr, gmtoff, nsec); |
202 | | -} |
203 | | - |
204 | | -int64_t |
205 | | -rust_timegm(rust_tm* timeptr) { |
206 | | - struct tm t; |
207 | | - rust_tm_to_tm(timeptr, &t); |
208 | | - return TIMEGM(&t); |
209 | | -} |
210 | | - |
211 | | -int64_t |
212 | | -rust_mktime(rust_tm* timeptr) { |
213 | | - struct tm t; |
214 | | - rust_tm_to_tm(timeptr, &t); |
215 | | - return mktime(&t); |
216 | | -} |
217 | | - |
218 | 80 | #ifndef _WIN32 |
219 | 81 |
|
220 | 82 | DIR* |
|
0 commit comments