1N/A/*
1N/A *
1N/A * Copyright 1998 Sun Microsystems, Inc. All rights reserved.
1N/A * Use is subject to license terms.
1N/A *
1N/A *
1N/A * Comments:
1N/A *
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include <stdlib.h>
1N/A#include <string.h>
1N/A#include <ctype.h>
1N/A
1N/Astatic char hexdig[] = "0123456789abcdef";
1N/A
1N/Achar* hexa_print(char *aString, int aLen)
1N/A{
1N/A char *res;
1N/A int i =0;
1N/A
1N/A if ((res = (char *)calloc (aLen*2 + 1, 1 )) == NULL){
1N/A return (NULL);
1N/A }
1N/A for (;;){
1N/A if (aLen < 1)
1N/A break;
1N/A res[i] = hexdig[ ( *aString & 0xf0 ) >> 4 ];
1N/A res[i + 1] = hexdig[ *aString & 0x0f ];
1N/A i+= 2;
1N/A aLen--;
1N/A aString++;
1N/A }
1N/A return (res);
1N/A}
1N/A
1N/A
1N/Astatic int
1N/Aunhex( char c )
1N/A{
1N/A return( c >= '0' && c <= '9' ? c - '0'
1N/A : c >= 'A' && c <= 'F' ? c - 'A' + 10
1N/A : c - 'a' + 10 );
1N/A}
1N/A
1N/Achar * hexa2str(char *anHexaStr, int *aResLen) {
1N/A int theLen = 0;
1N/A char *theRes = malloc(strlen(anHexaStr) /2 + 1);
1N/A
1N/A while (isxdigit(*anHexaStr)){
1N/A theRes[theLen] = unhex(*anHexaStr) << 4;
1N/A if (++anHexaStr != '\0'){
1N/A theRes[theLen] += unhex(*anHexaStr);
1N/A anHexaStr++;
1N/A }
1N/A theLen++;
1N/A }
1N/A theRes[theLen] = '\0';
1N/A * aResLen = theLen;
1N/A return (theRes);
1N/A}