OpenVMS Source-Code Demos

SYS_CREATE_UID_101.C

//=====================================================================================================
// title   : sys_create_uid_101.c
// author  : Neil Rieck
// created : 2011-10-21
// platform: HP C V7.3-009 on OpenVMS Alpha V8.4
// notes   : part of this program is derived from "sys_create_uid.c" by James F Duff
//		found here:	http://www.eight-cubed.com/examples/framework.php?file=sys_create_uid.c
//           part of this program is derived from "GUID tips: GUID UUID and WWID format, structure"
//		found here:	http://labs.hoffmanlabs.com/node/717
//=====================================================================================================
#define PROGRAM_VER	"sys_create_uid_101.c"		//
#include <stdio.h>					//
#define __NEW_STARLET	1				// enable new (strict) starlet for OpenVMS Alpha 7.0 and later
							// http://h71000.www7.hp.com/doc/82final/5841/5841pro_059.html
#include <starlet.h>					// vms specific
#include <ssdef.h>					// vms specific
//
int main() {
	union {						//
	    unsigned int uid[4];			// sizeof = 16 (128 bits)
	    struct {					//
		unsigned long   data0;			// 32-bits	32
		unsigned short  data1;			// 16-bits	48
		unsigned short  data2;			// 16-bits	64
		unsigned char   data3[8];		// 64-bits	128
	    } guid;					// sizeof = 16 (128 bits)
	} u2;						//
	unsigned long int rc;				//
	//
	printf("program: %s\n", PROGRAM_VER);		//
	rc = sys$create_uid (u2.uid);			//
//	rc = sys$create_uid (&u2.uid);			// not legal with _NEW_STARLET
	if ((rc & 7)!=SS$_NORMAL) {			//
	    printf("-e-sys$create_uid: %d\n", rc);	//
	    return(rc);					// abort with the error code
	}

	//
	//	form #1 (uid) 32 hex plus 3 superfluous dashes
	//
	(void) printf("uid : %08lX.%08lX.%08lX.%08lX\n",
			u2.uid[0],
			u2.uid[1],
			u2.uid[2],
			u2.uid[3]);
	//
	//	form #2 (guid) 32 hex plus 4 superfluous dashes
	//	also see: http://en.wikipedia.org/wiki/Globally_unique_identifier
	//
	printf( "guid: %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
		u2.guid.data0   ,
		u2.guid.data1   ,
		u2.guid.data2   ,
		u2.guid.data3[0], u2.guid.data3[1],
		u2.guid.data3[2], u2.guid.data3[3], u2.guid.data3[4], u2.guid.data3[5], u2.guid.data3[6], u2.guid.data3[7] );
	//
	//	adios
	//
	return(SS$_NORMAL);				// vms-success
}