Ignore:
Timestamp:
Jul 17, 2000, 12:43:41 AM (25 years ago)
Author:
bird
Message:

Checkin of current code in the Grace brance for backup purpose.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GRACE/src/win32k/misc/env.c

    r3412 r3834  
    1 /* $Id: env.c,v 1.2 2000-04-17 02:26:04 bird Exp $
     1/* $Id: env.c,v 1.2.4.1 2000-07-16 22:43:39 bird Exp $
    22 *
    33 * Environment access functions
     
    1414#define INCL_DOSERRORS                  /* Error codes */
    1515#define INCL_OS2KRNL_VM                 /* OS2KRNL: Virtual Memory Management */
    16 
     16#define INCL_OS2KRNL_PTDA               /* OS2KNRL: (per)ProcessTaskDataArea */
    1717
    1818/*******************************************************************************
     
    2424#include "dev32hlp.h"
    2525#include "log.h"
    26 #include "ptda.h"
    2726#include "OS2Krnl.h"
    2827#include <string.h>
    29 
     28#include "macros.h"
    3029#include "env.h"
    3130
     
    3938 * @param     paszEnv   Pointer to the environment data to search.
    4039 *                      The environment data is a list of zero-strings terminated
    41  *                      by an empty string. The strings are paired, that means
    42  *                      that the first string is the variable name and the
    43  *                      following string is the value of the variable.
    44  *                      AFAIK a variable can't have an empty value string!
    45  * @param     pszVar    Name of the environment variable to find.
     40 *                      by an empty string. The strings consists of two parts which
     41 *                      are separated by a euqal char ('='). The first part is the
     42 *                      variable name. The second part is the value of the variable.
     43 *
     44 *                      IF this is NULL we'll simply return NULL.
     45 * @param     pszVar    Name of the environment variable to find. (NULL not allowed.)
    4646 */
    4747const char *ScanEnv(const char *paszEnv, const char *pszVar)
    4848{
     49    int     cchVar;
     50    /*
     51     * Return if environment not found.
     52     */
     53    #ifdef DEBUG
     54    if (pszVar < (const char *)0x10000 || *pszVar == '\0')
     55        kprintf(("ScanEnv: Invalid parameter pszVar (%p)\n", pszVar));
     56    #endif
     57    if (paszEnv == NULL)
     58        return NULL;
     59    #ifdef DEBUG
     60    if (paszEnv < (const char *)0x10000)
     61        kprintf(("ScanEnv: Invalid parameter paszEnv (%p)\n", paszEnv));
     62    #endif
     63
    4964    /*
    5065     * Loop thru the environment data until an empty string is reached.
    5166     */
     67    cchVar = strlen(pszVar);
    5268    while (*paszEnv != '\0')
    5369    {
    54         register int i;                 /* Variable use to store the compare result. */
    55 
    5670        /*
    57          * Variable name.
    58          * Check if it's matching the name we're searching for and skip the variable name.
     71         * Check if the variable name is it's matching the one we're searching for.
    5972         */
    60         i = stricmp(paszEnv, pszVar);
    61         paszEnv += strlen(paszEnv) + 1;
    62         if (i == 0)
    63         {   /* Variable was found. Return pointer to the value. */
    64             return paszEnv;
     73        const char *pszEqual = strchr(paszEnv, '=');
     74        if (pszEqual != NULL && (pszEqual - paszEnv) == cchVar
     75            && memcmp(paszEnv, pszVar, cchVar) == 0
     76            )
     77        {
     78            /*
     79             * Variable was found. Return pointer to the value.
     80             */
     81            return pszEqual + 1;
    6582        }
    6683
    6784        /*
    68          * !Paranoia!
    69          * If no value string we'll quit. This may be an IPE, if not it might
    70          * cause one if we continue processing the environment data.
     85         * Skip this variable. (Don't use pszEqual since it might be NULL)
    7186         */
    72         if (*paszEnv == '\0')
    73             break;
    74 
    75         /* Skip value */
    7687        paszEnv += strlen(paszEnv) + 1;
    7788    }
     
    8293
    8394/**
    84  * Get the linear pointer to the environment data.
     95 * Get the linear pointer to the environment data for the current
     96 * process or the process being started (EXECed).
    8597 *
    86  * @returns   Pointer to environment data.
    87  *            NULL on failure.
     98 * @param       fExecChild      TRUE:  Get exec child environment.
     99 *                                     (Not supported by method 2)
     100 *                              FALSE: Get current process environment.
     101 * @returns     Pointer to environment data.
     102 *              NULL on failure.
    88103 */
    89 const char *GetEnv(void)
     104const char *GetEnv(BOOL fExecChild)
    90105{
    91     /*  There is probably two ways of getting the environment data for a the
     106    /*  There are probably two ways of getting the environment data for the
    92107     *  current process: 1) get it from the PTDA->ptda_environ
    93108     *                   2) Local infosegment (LIS from GetDosVar devhlp)
    94      *  I am not sure which one of these works best. What I know is that
     109     *  I am not sure which one of these which works best. What I know is that
    95110     *  method 1) is used by the w_GetEnv API worker. This API is called at
    96111     *  Ring-0 from some delete file operation. (Which uses it to get the
     
    98113     *  I don't want to thunk around using that. There for I'll implement
    99114     *  my own GetEnv. So, currently I'll write the code for both 1) and
    100      *  2), testing will show which one of them are most handy.
     115     *  2), testing will show which one of them are the better.
    101116     */
    102117
     
    116131     */
    117132    pPTDACur = ptdaGetCur();
    118     if (pPTDA != NULL)
     133    if (pPTDACur != NULL)
    119134    {
    120         pPTDA = ptdaGet_pPTDAExecChild(pPTDA);
    121         if (pPTDA != NULL)
     135        pPTDA = ptdaGet_pPTDAExecChild(pPTDACur);
     136        if (pPTDA != NULL && fExecChild)
    122137        {
    123138            hobEnviron = ptdaGet_ptda_environ(pPTDA);
     
    127142                if (rc == NO_ERROR)
    128143                    return (const char *)ulAddr;
    129                 kprintf(("GetEnv: VMObjHandleInfo failed with rc=%d for hob=0x%04x\n", rc, hobEnviron));
     144                kprintf(("GetEnv: (1) VMObjHandleInfo failed with rc=%d for hob=0x%04x \n", rc, hobEnviron));
    130145            }
    131146        }
     
    135150        {
    136151            rc = VMObjHandleInfo(hobEnviron, SSToDS(&ulAddr), SSToDS(&ushPTDA));
    137             if (rc != NO_ERROR)
    138             {
    139                 kprintf(("GetEnv: VMObjHandleInfo failed with rc=%d for hob=0x%04x\n", rc, hobEnviron));
    140             }
     152            if (rc == NO_ERROR)
     153                return (const char *)ulAddr;
     154            kprintf(("GetEnv: (2) VMObjHandleInfo failed with rc=%d for hob=0x%04x\n", rc, hobEnviron));
    141155        }
    142156    }
    143157    else
    144     {
     158    {   /* Not called at task time? No current task! */
    145159        kprintf(("GetEnv: Failed to get current PTDA.\n"));
    146160    }
    147161
    148     return (const char *)ulAddr;
     162    return NULL;
     163
    149164
    150165    #else
     166
    151167
    152168    struct InfoSegLDT * pLIS;           /* Pointer to local infosegment. */
     
    162178    {
    163179        kprintf(("GetEnv: Failed to get local info segment\n"));
     180        NOREF(fExecChild);
    164181        return NULL;
    165182    }
Note: See TracChangeset for help on using the changeset viewer.