Logo Search packages:      
Sourcecode: virtualbox-ose version File versions  Download package

static KU32 kPrfGetEnvValue ( const char *  pszVar,
KU32  uDefault 
) [static]

The the value of an env.var.

Returns:
The value of the env.var.

The default if the value was not found.

Parameters:
pszVar The variable name.
uDefault The default value.

Definition at line 1215 of file kProfileR3.cpp.

Referenced by kPrfInitialize().

{
#if K_OS == K_OS_WINDOWS
    char szBuf[128];
    const char *pszValue = szBuf;
    if (!GetEnvironmentVariable(pszVar, szBuf, sizeof(szBuf)))
        pszValue = NULL;

#elif K_OS == K_OS_OS2
    PSZ pszValue;
    if (DosScanEnv((PCSZ)pszVar, &pszValue))
        pszValue = NULL;

#else
    const char *pszValue = getenv(pszVar);

#endif

    /*
     * Discard the obvious stuff.
     */
    if (!pszValue)
        return uDefault;
    while (*pszValue == ' ' || *pszValue == '\t')
        pszValue++;
    if (!*pszValue)
        return uDefault;

    /*
     * Interpret the value.
     */
    unsigned    uBase = 10;
    KU32        uValue = 0;
    const char *psz = pszValue;

    /* prefix - only hex */
    if (*psz == '0' && (psz[1] == 'x' || psz[1] == 'X'))
    {
        uBase = 16;
        psz += 2;
    }

    /* read the value */
    while (*psz)
    {
        unsigned char ch = (unsigned char)*psz;
        if (ch >= '0' && ch <= '9')
            ch -= '0';
        else if (   uBase > 10
                 && ch >= 'a' && ch <= 'f')
            ch -= 'a' + 10;
        else if (   uBase > 10
                 && ch >= 'a' && ch <= 'F')
            ch -= 'a' + 10;
        else
            break;
        uValue *= uBase;
        uValue += ch;
        psz++;
    }

    /* postfixes */
    switch (*psz)
    {
        case 'm':
        case 'M':
            uValue *= 1024*1024;
            break;

        case 'k':
        case 'K':
            uValue *= 1024;
            break;
    }

    /*
     * If the value is still 0, we return the default.
     */
    return uValue ? uValue : uDefault;
}


Generated by  Doxygen 1.6.0   Back to index