Decoding the VMS 64bit timestamp...

/* timecvt.c 9-Apr-97 15:30:04 by Kevin D. Quitt

u2vtime Convert UNIX seconds to VMS clunks.

v2utime Convert VMS clunks to UNIX seconds

Unix time is a 32-bit count of seconds after midnight, January 1, 1970.

VMS time is a 64-bit count of 100 ns intervals since midnight, November

17, 1858

NOTE: These routines do NOT accomodate leap seconds that have been

inserted

for calendar accuracy.

*/

#define HIW(x) ((unsigned int)(((x) >> 16) & 0xFFFF))

#define LOW(x) ((unsigned int)( (x) & 0xFFFF))

/* Delta is the number of seconds from 17-Nov-1858 to 1-Jan-1970

Scale converts between seconds and clunks (100ns)

#define DELTA ((unsigned long long)3538252800L)

#define SCALE ((unsigned long)10000000L)

*/

#define SCALE1 ((unsigned short)10000)

#define SCALE2 ((unsigned short)1000)

#define DELTAH (0xD2E5)

#define DELTAL (0x7400)

static unsigned short Delta[4] = { DELTAL, DELTAH, 0, 0 };

/* Full 64+64 bit add

*/

static int add( from, to )

unsigned short *from, *to;

{

unsigned int partial, i;

for ( i = 0; i < 4; i++ )

{

partial = from[ i ] + to[ i ];

to[ i ] = LOW(partial);

partial = HIW(partial);

}

}

/* 64-64 bit subtract

*/

static int subtract( diminuend, subtrahend )

unsigned short *diminuend, *subtrahend;

{

unsigned int partial, i, j;

for ( i = 0; i < 2; i++ )

{

partial = subtrahend[ i ];

if ( subtrahend[ i ] < diminuend[ i ] )

{

for ( j = i + 1; j < 3 ; j++ )

{

if ( --subtrahend[ i ] != (unsigned short)0xFFFF )

break;

}

partial += 0x10000;

}

partial -= diminuend[ i ];

subtrahend[ i ] = LOW(partial);

}

}

/* 64*16 bit multiply

*/

static int multiply( multiplier, multiplicand )

unsigned short multiplier, *multiplicand;

{

unsigned int partial, carry, i;

carry = 0;

for ( i = 0; i < 4; i++ )

{

partial = multiplicand[ i ];

partial = partial * multiplier + carry;

multiplicand[ i ] = LOW(partial);

carry = HIW(partial);

}

}

/* 64/16 bit divide

*/

static int divide( divisor, dividend )

unsigned short divisor, *dividend;

{

unsigned int partial, borrow, i;

borrow;

for ( i = 3; i >-1; i-- )

{

partial = (borrow << 16) + dividend[ i ];

borrow = partial % divisor;

dividend[ i ] = partial / divisor;

}

}

/* Clunks are: SCALE * (seconds + DELTA)

*/

int u2vtime( seconds, clunk )

unsigned int seconds; unsigned short *clunk;

{

clunk[ 0 ] = LOW( seconds );

clunk[ 1 ] = HIW( seconds );

add( Delta, clunk );

multiply( SCALE1, clunk );

multiply( SCALE2, clunk );

}

/* Seconds are: clunks / SCALE - DELTA

*/

unsigned int v2utime( clunk )

unsigned short *clunk;

{

unsigned int seconds;

divide( SCALE1, clunk );

divide( SCALE2, clunk );

subtract( Delta, clunk );

seconds = clunk[ 1 ];

seconds = (seconds << 16) + clunk[ 0 ];

return seconds;

}

--

#include <standard.disclaimer>

_

Kevin D Quitt USA 91351-4454 96.37% of all statistics are made up

Per the FCA, this email address may not be added to any commercial mail list