/*
VMS time -> unix time_t conversion */
/* Author: Joseph Huber huber @ mppmu.mpg.de */
#include stddef
#include stdlib
#include time
#include starlet
#include unixlib
#ifndef __vax
void vmstime_to_time_t(__int64 *vmstime, time_t *epoch)
#else
/*to make it working even on older Vax systems*/
void vmstime_to_time_t(void *vmstime, time_t *epoch)
#endif
/* vmstime: pointer to VMS quadword time (absolute time)
epoch: pointer to store epoch time
No attempt is made to handle error cases: invalid VMS time inputs or
times before Unix epoch.
*/
{
struct tm tm;
unsigned short numtim[8];
*epoch = time(0);
#ifdef DECCFIX
/* use decc$fix_time */
/*
looks like the easiest, but:
treats the VMS quad time as GMT, not local time.
The result epoch time is then added the GMT offset when printing!
*/
*epoch = decc$fix_time(vmstime);
#else /* before I learned about decc$fix-time ;-) */
(void)localtime_r(epoch, &tm); /* preset fields like GMT offset*/
/* not sure if the DST flag is o.k.*/
/* but we don't know it from vmstime anyway */
(void) sys$numtim(numtim,vmstime);
tm.tm_year = numtim[0] - 1900;
tm.tm_mon = numtim[1] - 1;
tm.tm_mday = numtim[2];
tm.tm_hour = numtim[3];
tm.tm_min = numtim[4];
tm.tm_sec = numtim[5];
tm.tm_wday = tm.tm_yday = 0;
*epoch = mktime(&tm);
#endif
}
#ifdef TEST
#include stdio
int main() {
time_t unixtime;
#ifndef __vax
__int64 datenow;
(void) sys$gettim(&datenow);
vmstime_to_time_t(&datenow,&unixtime);
#else
long datenow[2];
(void) sys$gettim(datenow);
vmstime_to_time_t(datenow,&unixtime);
#endif
printf("Time is: %s\n",ctime(&unixtime));
return 0;
}
#endif