Trusted Solaris Developer's Guide

Binary and Hexadecimal

There are two types of binary to hexadecimal routines: regular and reentrant. Both types of routines return a pointer to a string that contains the result of the translation or NULL if the clearance passed in is not type bclear_t.

Regular

This example translates the binary process clearance to hexadecimal and back.

#include <tsol/label.h>

main()
{
	int          retval;
	bclear_t     hclear;
	char         *string ;

	retval = getclearance(&hclear);

	if((string = bcleartoh(&hclear)) != 0)
		printf("Hex string = %s\n", string);

	retval = htobclear(string, &hclear);
	printf("Return Value = %d\n", retval);
}

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


Hex string = 0xClearance hexadecimal value

The second printf statement prints the following where non-zero indicates a successful translation:


Return Value = 1

Reentrant

The reentrant (MT-SAFE) routine bcleartoh_r(3TSOL) requires the allocation and freeing of memory for the value returned. The h_alloc(3TSOL) routine is used to allocate this memory, sizing it appropriately for the type of label (in this case hexadecimal) to be converted.

type where type is a hexadecimal value that indicates that a defined clearance (SUN_CLR_ID) is translated to hexadecimal.

This example allocates memory for the translation type, translates the binary process clearance to hexadecimal, and frees the memory at the end.

#include <tsol/label.h>

main()
{
	bclear_t     hclear;
	char         *string, *hex;

	getclearance(&hclear);
	hex = h_alloc(SUN_CLR_ID);
	if((string = bcleartoh_r(&hclear, hex)) != 0);
		printf("Hex string = %s\n", string);

	h_free(hex);
}

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


Hex string = 0x0006cc0000000000000000000000000000000000000 
000000003ffffffffffff0000