Ignore:
Timestamp:
Sep 2, 2007, 10:05:39 PM (18 years ago)
Author:
bird
Message:

env, paths, page allocation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/kStuff/kHlp/Bare/kHlpBareEnv.c

    r3573 r3575  
    4343
    4444
    45 /**
    46  * Get an environment variable.
    47  *
    48  * @returns 0 on success.
    49  * @returns KERR_BUFFER_OVERFLOW on if the buffer is too small.
    50  * @returns KERR_ENVVAR_NOT_FOUND if not found.
    51  * @returns OS specfic status code on other error.
    52  * @param   pszVar      The variable name.
    53  * @param   pszVal      Where to store the value.
    54  * @param   cchVal      The size of the buffer pointed to by pszVal.
    55  */
    56 int     kHlpGetEnv(const char *pszVar, char *pszVal, KSIZE cchVal)
     45KHLP_DECL(int) kHlpGetEnv(const char *pszVar, char *pszVal, KSIZE cchVal)
    5746{
    5847#if K_OS == K_OS_OS2
     
    7160    }
    7261    else
    73         rc = KERR_ENV_VAR_NOT_FOUND;
     62        rc = KERR_ENVVAR_NOT_FOUND;
    7463    return rc;
    7564
    76 #elif  K_OS == K_OS_WINDOWS
     65#elif K_OS == K_OS_WINDOWS
    7766    DWORD cch;
    7867
     
    9483}
    9584
    96 
    97 /**
    98  * Gets an environment variable and converts it to a KSIZE.
    99  *
    100  * @returns 0 and *pcb on success.
    101  * @returns On failure see kHlpGetEnv.
    102  * @param   pszVar  The name of the variable.
    103  * @param   pcb     Where to put the value.
    104  */
    105 int     kHlpGetEnvUZ(const char *pszVar, KSIZE *pcb)
    106 {
    107     KSIZE       cb;
    108     unsigned    uBase;
    109     char        szVal[64];
    110     KSIZE       cchVal = sizeof(szVal);
    111     const char *psz;
    112     int         rc;
    113 
    114     *pcb = 0;
    115     rc = kHlpGetEnv(pszVar, szVal, cchVal);
    116     if (rc)
    117         return rc;
    118 
    119     /* figure out the base. */
    120     uBase = 10;
    121     psz = szVal;
    122     if (    *psz == '0'
    123         &&  (psz[1] == 'x' || psz[1] == 'X'))
    124     {
    125         uBase = 16;
    126         psz += 2;
    127     }
    128 
    129     /* convert it up to the first unknown char. */
    130     cb = 0;
    131     for(;;)
    132     {
    133         const char ch = *psz;
    134         unsigned uDigit;
    135         if (!ch)
    136             break;
    137         else if (ch >= '0' && ch <= '9')
    138             uDigit = ch - '0';
    139         else if (ch >= 'a' && ch <= 'z')
    140             uDigit = ch - 'a' + 10;
    141         else if (ch >= 'A' && ch <= 'Z')
    142             uDigit = ch - 'A' + 10;
    143         else
    144             break;
    145         if (uDigit >= uBase)
    146             break;
    147 
    148         /* add the digit */
    149         cb *= uBase;
    150         cb += uDigit;
    151 
    152         psz++;
    153     }
    154 
    155     /* check for unit */
    156     if (*psz == 'm' || *psz == 'M')
    157         cb *= 1024*1024;
    158     else if (*psz == 'k' ||*psz == 'K')
    159         cb *= 1024;
    160     else if (*psz == 'g' || *psz == 'G')
    161         cb *= 1024*1024*1024;
    162 
    163     *pcb = cb;
    164     return 0;
    165 }
    166 
Note: See TracChangeset for help on using the changeset viewer.