@@ -5,6 +5,7 @@ char *version = "VMSBACKUP4.3";
55#include <stdio.h>
66#include <stdlib.h>
77#include <getopt.h>
8+ #include <errno.h>
89#include "vmsbackup.h"
910#include "sysdep.h"
1011
@@ -167,22 +168,53 @@ int main (int argc, char *argv[])
167168/* Given an 8-byte VMS-format date (little-endian) in SRCTIME, put an
168169 ASCII representation in *ASCBUFFER and put the length in *ASCLENGTH.
169170 ASCBUFFER must be big enough for 23 characters.
170- Returns: condition code. */
171+ Returns: condition code. (SS$_NORMAL == 1 for success) */
171172#ifdef HAVE_STARLET
172- int time_vms_to_asc (short * asclength , char * ascbuffer , void * srctime )
173+ int time_vms_to_asc (short * asclength , char * ascbuffer , void * srctime , int srclen )
173174{
174175 struct dsc$descriptor buffer ;
175176
177+ if (srclen != 8 )
178+ return SS$_INSFARG ;
176179 buffer .dsc$w_length = 23 ;
177180 buffer .dsc$b_dtype = DSC$K_DTYPE_T ;
178181 buffer .dsc$b_class = DSC$K_CLASS_S ;
179182 buffer .dsc$a_pointer = ascbuffer ;
180183 return sys$asctim (asclength , & buffer , srctime , 0 );
181184}
182185#else
183- int time_vms_to_asc (short * asclength , char * ascbuffer , void * srctime )
186+ #include <time.h>
187+ #include <string.h>
188+ #include "hexdump.h"
189+ /* See OpenVMS programming concepts manual volume 2, section 11.1
190+ "The time value is a binary number in 100-nanosecond (ns) units offset
191+ from the system base date and time, which is 00:00 o'clock,
192+ November 17, 1858 (the Smithsonian base date and time for the astronomic calendar).
193+
194+ 1 second = 10 million * 100 ns
195+
196+ returns 1 for success
197+ */
198+
199+ int time_vms_to_asc (short * asclength , char * ascbuffer , void * srctime , int srclen )
184200{
185- * asclength = 0 ;
201+ unsigned long long tval = 0 ;
202+ if (srclen != sizeof (long long )) {
203+ errno = EINVAL ;
204+ return 0 ;
205+ }
206+ /* get srctime as 64bit little endian to tval */
207+ memcpy (& tval , srctime , srclen );
208+ // printf("time_vms_to_asc %lld\n", tval);
209+ // hexdump((unsigned char *)&tval, 8, stdout);
210+ tval /= (10LL * 1000 * 1000 ); /* to seconds */
211+ // printf("time_vms_to_asc seconds %lld\n", tval);
212+ /* 17-Nov-1858 to 1-Jan-1970: 40587 days */
213+ tval -= (40587LL * 24 * 60 * 60 ); /* to epoch (1-Jan-1970) */
214+ // printf("time_vms_to_asc epoch %lld >%s<\n", tval, ctime((time_t *)&tval));
215+ * asclength = 24 ;
216+ strncpy (ascbuffer , ctime ((time_t * )& tval ), * asclength );
217+
186218 return 1 ;
187219}
188220#endif
0 commit comments