Move hextobin as virHexToBin to util.c

virHexToBin will be used in the .vmx handling code.
This commit is contained in:
Matthias Bolte 2010-08-27 23:13:45 +02:00
parent 09d37bdef5
commit 1fe2927a34
3 changed files with 19 additions and 18 deletions

View File

@ -2089,6 +2089,21 @@ virStrToDouble(char const *s,
return 0;
}
/* Convert C from hexadecimal character to integer. */
int
virHexToBin(unsigned char c)
{
switch (c) {
default: return c - '0';
case 'a': case 'A': return 10;
case 'b': case 'B': return 11;
case 'c': case 'C': return 12;
case 'd': case 'D': return 13;
case 'e': case 'E': return 14;
case 'f': case 'F': return 15;
}
}
/**
* virSkipSpaces:
* @str: pointer to the char pointer used

View File

@ -194,6 +194,8 @@ int virStrToDouble(char const *s,
char **end_ptr,
double *result);
int virHexToBin(unsigned char c);
int virMacAddrCompare (const char *mac1, const char *mac2);
void virSkipSpaces(const char **str);

View File

@ -113,22 +113,6 @@ virUUIDGenerate(unsigned char *uuid)
return(err);
}
/* Convert C from hexadecimal character to integer. */
static int
hextobin (unsigned char c)
{
switch (c)
{
default: return c - '0';
case 'a': case 'A': return 10;
case 'b': case 'B': return 11;
case 'c': case 'C': return 12;
case 'd': case 'D': return 13;
case 'e': case 'E': return 14;
case 'f': case 'F': return 15;
}
}
/**
* virUUIDParse:
* @uuidstr: zero terminated string representation of the UUID
@ -166,14 +150,14 @@ virUUIDParse(const char *uuidstr, unsigned char *uuid) {
}
if (!c_isxdigit(*cur))
goto error;
uuid[i] = hextobin(*cur);
uuid[i] = virHexToBin(*cur);
uuid[i] *= 16;
cur++;
if (*cur == 0)
goto error;
if (!c_isxdigit(*cur))
goto error;
uuid[i] += hextobin(*cur);
uuid[i] += virHexToBin(*cur);
i++;
cur++;
}