cfgldrhlp.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/** @file
*
* CFGLDRHLP - Configuration Loader Helpers
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
#ifdef __WIN__
# if _MSC_VER < 1400
/// @todo Without this I cannot get the stuff to
// link. I don't know where it should come from.
// bird: This is probably a __declspec(import) type var; thing. So, using the right
// compiler options (i.e. template) should cure the problem I guess.
# include <ctype.h>
extern "C"
{
int __mb_cur_max = 1;
int errno;
}
# endif
#endif /* __WIN__ */
#include "cfgldrhlp.h"
#include <stdio.h>
#include <ctype.h>
#include <limits.h>
{
return hexdigit - '0';
return 0xFF; // error indicator
}
{
}
{
int rc = VINF_SUCCESS;
// skip leading spaces
while (*p <= 0xFF && isspace ((char)*p))
{
p++;
}
// autodetect base
unsigned base = 10;
if (*p == '0')
{
p++;
if (*p == 'x' || *p == 'X')
{
p++;
base = 16;
}
else
{
base = 8;
}
}
// p points to the first character in the string, start conversion
while (*p)
{
unsigned digit;
// check the unicode character to be within ASCII range
if (*p > 0x7F)
{
break;
}
if (isdigit ((char)*p))
{
digit = *p - '0';
}
else if ('a' <= *p && *p <= 'f')
{
}
else if ('A' <= *p && *p <= 'F')
{
}
else
{
break;
}
{
break;
}
/// @todo overflow check
p++;
}
if (VBOX_SUCCESS(rc))
{
}
return rc;
}
{
int rc = VINF_SUCCESS;
char *p = pszValue;
if (base == 16)
{
*p++ = '0';
*p++ = 'x';
}
// remember start of the digit string
char *s = p;
for (;;)
{
if (base == 16)
{
}
else
{
*p++ = digit + '0';
}
if (ullValue == 0)
{
break;
}
}
*p = 0;
// reverse the resulting string
p--; // skip trailing nul
while (s < p)
{
char tmp = *s;
*s++ = *p;
*p-- = tmp;
}
return rc;
}
{
if (VBOX_SUCCESS(rc))
{
{
}
else
{
}
}
return rc;
}
{
}
{
}
// Note: 64 bit values are converted to hex notation
{
}
// converts a string of hex digits to memory bytes
{
int rc = VINF_SUCCESS;
unsigned count = 0; // number of bytes those can be converted successfully from the puszValue
while (*puszValue)
{
if (b == 0xFF)
{
// it was not a valid hex digit
break;
}
{
*dst = b;
}
puszValue++;
if (!*puszValue)
{
break;
}
if (b == 0xFF)
{
// it was not a valid hex digit
break;
}
{
dst++;
}
count++;
}
return rc;
}
// convert memory bytes to UTF8 nul terminated string of hex values
{
int rc = VINF_SUCCESS;
// each byte will produce two hex digits and there will be nul terminator
if (!pszValue)
{
rc = VERR_NO_MEMORY;
}
else
{
unsigned i = 0;
{
}
*dst = 0;
}
return rc;
}
// releases memory buffer previously allocated by cfgldrhlp_bintostr
void cfgldrhlp_releasestr (char *pszValue)
{
if (pszValue)
{
}
}