Trusted Solaris Developer's Guide

Reentrant Binary and Hexadecimal Label Translation Routines

The reentrant (MT-SAFE) routine bcltoh_r(3TSOL) requires the allocation and freeing of memory for a variable of the specified type. This example allocates memory, translates the binary CMW label to hexadecimal, and frees the memory at the end. Converting a sensitivity label to hexadecimal and back is a similar process.

#include <tsol/label.h>
#include <stdio.h>

main()
{
	int retval;
	bclabel_t hcmwlabel, hexcmw;
	char *string, *hex;

	getcmwplabel(&hcmwlabel);
	hex = h_alloc(SUN_CMW_ID);
	if((string = bcltoh_r(&hcmwlabel, hex)) != NULL)
		printf("Hex string = %s\n", string);

	retval = htobcl(string, &hexcmw);
	printf("Return Value = %d\n", retval);
	h_free(hex);
}

The printf statement prints the binary clearance in the following hexadecimal format:


Hex string =0x00000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000[0x00040c0000000000000000000000
000000000000000000000003ffffffffffff0000]

Return Value = 1