From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 16-NOV-1988 21:03
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Need to convert VMS time to Unix time


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Wed, 16 NOV 88 09:57:58 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Wed, 16 Nov 88 09:53:28 PST
Received: by ucbvax.Berkeley.EDU (5.59/1.31)
	id AA12462; Mon, 14 Nov 88 13:10:16 PST
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 14 Nov 88 14:12:20 GMT
From: emcard!stiatl!todd@gatech.edu  (Todd Merriman)
Organization: Sales Technologies Inc., Atlanta, GA
Subject: Need to convert VMS time to Unix time
Message-Id: <1492@stiatl.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

I need to be able to convert VMS time to Unix time and vice-versa.  I have
written the following Macro code for a C function library.  Unfortunately,
It doesn't work!  Anyone know why?



       .IF DEFINED DOCUMENTATION
; ***************************************************************************
   Convert VMS to Unix time

   long vtout(vmstim)
      byte  vmstim [8];           /* (r) VMS time */

   Vtout() converts the VMS time to Unix time.  VMS time is stored as a 
   quad, and the "quad" may be implemented in C as an array of 8 unsigned
   chars.

   The equivalent Unix time
; ***************************************************************************
	.ENDC				; DOCUMENTATION

   	MU = 10000*1000			; VMS to Unix conversion factor
	.TITLE	VTOUT

	.PSECT	$DATA,PIC,USR,CON,REL,LCL,NOSHR,NOEXE,RD,WRT,NOVEC

$10:	.ASCID	/1-JAN-1970 0:0:0.0/	; Frank Zappa's birthday
ZAPPA:
	.ADDRESS $10			; address for shareable image

					; share a CODE PSECT with C functions
	.PSECT	$CODE,PIC,USR,CON,REL,LCL,SHR,EXE,RD,NOWRT,NOVEC
	.ENTRY VTOUT,^M<R2>
   	
   	CLRQ	-(SP)			; get space for quad
	PUSHL	SP			; arg 2 = quad time address
   	PUSHL	ZAPPA			; arg 1 = time descriptor address
	CALLS	#2,G^SYS$BINTIM		; get VMS time for Zappa's birthday

   	EDIV	#MU,@4(AP),R0,R2
   	EDIV	#MU,(SP),R1,R2
   	SUBL2	R0,R1
	RET

	.IF DEFINED DOCUMENTATION
; ***************************************************************************
   Convert Unix to VMS time

   void utovt(unixtim,vmstim)
      long  unixtim;             /* (r) Unix time */
      byte  vmstim [8];          /* (w) VMS time */

   Vtout() converts the VMS time to Unix time.  VMS time is stored as a 
   quad, and the "quad" may be implemented in C as an array of 8 unsigned
   chars.

   The equivalent Unix time
; ***************************************************************************
	.ENDC				; DOCUMENTATION

	.ENTRY UTOVT,^M<>
   	
   	CLRQ	-(SP)			; get space for quad
	PUSHL	SP			; arg 2 = quad time address
   	PUSHL	ZAPPA			; arg 1 = time descriptor address
	CALLS	#2,G^SYS$BINTIM		; get VMS time for Zappa's birthday

   	MOVL	#4,R0
   	EMUL	#MU,4(AP),#1,@8(AP)
   	ADDL2	@8(AP),(SP)
   	ADWC	@8(AP)[R0],4(SP)
	RET

	.END				; stop assembly here


/***************************************************************************
   C test program
***************************************************************************/
#include <stdio.h>
#include <ctype.h>

byte	vtime[8];
long 	curtime,
   	cvtime;

main()
{
   int	i;

   time(&curtime);			/* get Unix time */
   SYS$GETTIM(vtime);			/* get current VMS time */
   cvtime = vtout(vtime);
   
   for (i = 7; i >= 0; i--)
   	printf("%02X",vtime[i]);
   puts("");

   printf("Unix=%ld Converted vtime=%ld\r\n",
   	curtime,cvtime);
   utovt(curtime,vtime);

   for (i = 7; i >= 0; i--)
   	printf("%02X",vtime[i]);
   puts("");
}

; ***************************************************************************
; End VTOUT.MAR
; ***************************************************************************

