Commit 63593b22 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added function uuid2str() and str2uuid()

parent 541860a1
......@@ -324,6 +324,9 @@ void cdiInitialize(void);
void stream_write_record(int streamID, int memtype, const void *data, int nmiss);
void uuid2str(const char *uuid, char *uuidstr);
void str2uuid(const char *uuidstr, char *uuid);
#endif /* _STREAM_INT_H */
/*
......
......@@ -20,27 +20,27 @@ void cdiPrintDatatypes(void)
/* IsBigendian returns 1 for big endian byte order */
static union {unsigned long l; unsigned char c[sizeof(long)];} u_byteorder = {1};
fprintf (stderr, "+-------------+-------+\n");
fprintf (stderr, "| types | bytes |\n");
fprintf (stderr, "+-------------+-------+\n");
fprintf (stderr, "+-------------+-------+\n");
fprintf (stderr, "| types | bytes |\n");
fprintf (stderr, "+-------------+-------+\n");
fprintf (stderr, "| void * | %3d |\n", (int) sizeof(void *));
fprintf (stderr, "+-------------+-------+\n");
fprintf (stderr, "+-------------+-------+\n");
fprintf (stderr, "| char | %3d |\n", (int) sizeof(char));
fprintf (stderr, "+-------------+-------+\n");
fprintf (stderr, "+-------------+-------+\n");
fprintf (stderr, "| short | %3d |\n", (int) sizeof(short));
fprintf (stderr, "| int | %3d |\n", (int) sizeof(int));
fprintf (stderr, "| long | %3d |\n", (int) sizeof(long));
fprintf (stderr, "| long long | %3d |\n", (int) sizeof(long long));
fprintf (stderr, "| size_t | %3d |\n", (int) sizeof(size_t));
fprintf (stderr, "| off_t | %3d |\n", (int) sizeof(off_t));
fprintf (stderr, "+-------------+-------+\n");
fprintf (stderr, "+-------------+-------+\n");
fprintf (stderr, "| float | %3d |\n", (int) sizeof(float));
fprintf (stderr, "| double | %3d |\n", (int) sizeof(double));
fprintf (stderr, "| long double | %3d |\n", (int) sizeof(long double));
fprintf (stderr, "+-------------+-------+\n\n");
fprintf (stderr, "+-------------+-------+\n\n");
#define XSTRING(x) #x
#define STRING(x) XSTRING(x)
fprintf (stderr, "+-------------+-----------+\n");
fprintf (stderr, "+-------------+-----------+\n");
fprintf (stderr, "| INT32 | %-9s |\n", STRING(INT32));
fprintf (stderr, "| INT64 | %-9s |\n", STRING(INT64));
fprintf (stderr, "| FLT32 | %-9s |\n", STRING(FLT32));
......@@ -52,6 +52,49 @@ void cdiPrintDatatypes(void)
else
fprintf (stderr, "\n byte ordering is LITTLEENDIAN\n\n");
}
void uuid2str(const char *uuid, char *uuidstr)
{
int iret;
unsigned int ui[16];
if ( uuid == NULL ) return;
if ( uuidstr == NULL ) return;
uuidstr[0] = 0;
for ( int i = 0; i < 16; ++i ) ui[i] = (unsigned char) uuid[i];
iret = sprintf(uuidstr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
ui[0], ui[1], ui[2], ui[3], ui[4], ui[5], ui[6], ui[7],
ui[8], ui[9], ui[10], ui[11], ui[12], ui[13], ui[14], ui[15]);
if ( iret != 36 ) uuidstr[0] = 0;
}
void str2uuid(const char *uuidstr, char *uuid)
{
int iret;
unsigned int ui[16];
if ( uuid == NULL ) return;
if ( uuidstr == NULL ) return;
uuid[0] = 0;
if ( strlen(uuidstr) != 36 ) return;
iret = sscanf(uuidstr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
&ui[0], &ui[1], &ui[2], &ui[3], &ui[4], &ui[5], &ui[6], &ui[7],
&ui[8], &ui[9], &ui[10], &ui[11], &ui[12], &ui[13], &ui[14], &ui[15]);
if ( iret != 16 ) return;
for ( int i = 0; i < 16; ++i ) uuid[i] = ui[i];
}
/*
* Local Variables:
* c-file-style: "Java"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment