66 #ifdef OPENSSL_SYS_VMS
67 # if __CRTL_VER >= 70000000 && \
68 (defined _POSIX_C_SOURCE || !defined _ANSI_C_SOURCE)
69 # define VMS_GMTIME_OK
71 # ifndef VMS_GMTIME_OK
72 # include <libdtdef.h>
73 # include <lib$routines.h>
85 #if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_OS2) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r)) && !defined(OPENSSL_SYS_MACOSX) && !defined(OPENSSL_SYS_SUNOS)
88 gmtime_r(timer,result);
90 #elif !defined(OPENSSL_SYS_VMS) || defined(VMS_GMTIME_OK)
95 memcpy(result, ts,
sizeof(
struct tm));
98 #if defined( OPENSSL_SYS_VMS) && !defined( VMS_GMTIME_OK)
101 static $DESCRIPTOR(tabnam,
"LNM$DCL_LOGICAL");
102 static $DESCRIPTOR(lognam,
"SYS$TIMEZONE_DIFFERENTIAL");
104 unsigned int reslen = 0;
109 unsigned int *reslen;
111 { 0, LNM$_STRING, 0, 0 },
118 itemlist[0].buflen =
sizeof(logvalue);
119 itemlist[0].bufaddr = logvalue;
120 itemlist[0].reslen = &reslen;
121 status = sys$trnlnm(0, &tabnam, &lognam, 0, itemlist);
124 logvalue[reslen] =
'\0';
138 #if __CRTL_VER < 70000000 || defined _VMS_V6_SOURCE
140 status = atoi(logvalue);
174 unsigned long unix_epoch[2] = { 1273708544, 8164711 };
175 unsigned long deltatime[2];
176 unsigned long systime[2];
179 short year, month, day, hour, minute, second,
190 operation = LIB$K_DELTA_SECONDS;
191 status = lib$cvt_to_internal_time(&operation,
196 status = lib$add_times(unix_epoch, deltatime, systime);
199 status = sys$numtim(&time_values, systime);
202 result->tm_sec = time_values.second;
203 result->tm_min = time_values.minute;
204 result->tm_hour = time_values.hour;
205 result->tm_mday = time_values.day;
206 result->tm_mon = time_values.month - 1;
207 result->tm_year = time_values.year - 1900;
209 operation = LIB$K_DAY_OF_WEEK;
210 status = lib$cvt_from_internal_time(&operation,
211 &result->tm_wday, systime);
212 result->tm_wday %= 7;
214 operation = LIB$K_DAY_OF_YEAR;
215 status = lib$cvt_from_internal_time(&operation,
216 &result->tm_yday, systime);
219 result->tm_isdst = 0;
233 #define SECS_PER_DAY (24 * 60 * 60)
235 static long date_to_julian(
int y,
int m,
int d);
236 static void julian_to_date(
long jd,
int *y,
int *m,
int *d);
240 int offset_hms, offset_day;
242 int time_year, time_month, time_day;
247 offset_day += off_day;
249 offset_hms += tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec;
256 else if (offset_hms < 0)
265 time_year = tm->tm_year + 1900;
266 time_month = tm->tm_mon + 1;
267 time_day = tm->tm_mday;
269 time_jd = date_to_julian(time_year, time_month, time_day);
272 time_jd += offset_day;
279 julian_to_date(time_jd, &time_year, &time_month, &time_day);
281 if (time_year < 1900 || time_year > 9999)
286 tm->tm_year = time_year - 1900;
287 tm->tm_mon = time_month - 1;
288 tm->tm_mday = time_day;
290 tm->tm_hour = offset_hms / 3600;
291 tm->tm_min = (offset_hms / 60) % 60;
292 tm->tm_sec = offset_hms % 60;
301 static long date_to_julian(
int y,
int m,
int d)
303 return (1461 * (y + 4800 + (m - 14) / 12)) / 4 +
304 (367 * (m - 2 - 12 * ((m - 14) / 12))) / 12 -
305 (3 * ((y + 4900 + (m - 14) / 12) / 100)) / 4 +
309 static void julian_to_date(
long jd,
int *y,
int *m,
int *d)
312 long n = (4 * L) / 146097;
315 L = L - (146097 * n + 3) / 4;
316 i = (4000 * (L + 1)) / 1461001;
317 L = L - (1461 * i) / 4 + 31;
319 *d = L - (2447 * j) / 80;
321 *m = j + 2 - (12 * L);
322 *y = 100 * (n - 49) + i + L;
325 #ifdef OPENSSL_TIME_TEST
334 int main(
int argc,
char **argv)
337 for (offset = 0; offset < 1000000; offset++)
341 check_time(offset * 1000);
342 check_time(-offset * 1000);
346 int check_time(
long offset)
355 if ((tm1.tm_year == tm2.tm_year) &&
356 (tm1.tm_mon == tm2.tm_mon) &&
357 (tm1.tm_mday == tm2.tm_mday) &&
358 (tm1.tm_hour == tm2.tm_hour) &&
359 (tm1.tm_min == tm2.tm_min) &&
360 (tm1.tm_sec == tm2.tm_sec))
362 fprintf(stderr,
"TIME ERROR!!\n");
363 fprintf(stderr,
"Time1: %d/%d/%d, %d:%02d:%02d\n",
364 tm2.tm_mday, tm2.tm_mon + 1, tm2.tm_year + 1900,
365 tm2.tm_hour, tm2.tm_min, tm2.tm_sec);
366 fprintf(stderr,
"Time2: %d/%d/%d, %d:%02d:%02d\n",
367 tm1.tm_mday, tm1.tm_mon + 1, tm1.tm_year + 1900,
368 tm1.tm_hour, tm1.tm_min, tm1.tm_sec);