Ignore:
Timestamp:
Sep 2, 2000, 11:08:23 PM (25 years ago)
Author:
bird
Message:

Merged in the Grace branch. New Win32k!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/misc/env.c

    r3412 r4164  
    1 /* $Id: env.c,v 1.2 2000-04-17 02:26:04 bird Exp $
     1/* $Id: env.c,v 1.3 2000-09-02 21:08:13 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/*******************************************************************************
     
    2121#include <os2.h>
    2222
     23#include "devSegDf.h"                   /* Win32k segment definitions. */
    2324#include "dev32.h"
    2425#include "dev32hlp.h"
    2526#include "log.h"
    26 #include "ptda.h"
    2727#include "OS2Krnl.h"
    2828#include <string.h>
    29 
     29#include "macros.h"
    3030#include "env.h"
    3131
     
    3939 * @param     paszEnv   Pointer to the environment data to search.
    4040 *                      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.
     41 *                      by an empty string. The strings consists of two parts which
     42 *                      are separated by a euqal char ('='). The first part is the
     43 *                      variable name. The second part is the value of the variable.
     44 *
     45 *                      IF this is NULL we'll simply return NULL.
     46 * @param     pszVar    Name of the environment variable to find. (NULL not allowed.)
    4647 */
    4748const char *ScanEnv(const char *paszEnv, const char *pszVar)
    4849{
     50    int     cchVar;
     51    /*
     52     * Return if environment not found.
     53     */
     54    #ifdef DEBUG
     55    if (pszVar < (const char *)0x10000 || *pszVar == '\0')
     56        kprintf(("ScanEnv: Invalid parameter pszVar (%p)\n", pszVar));
     57    #endif
     58    if (paszEnv == NULL)
     59        return NULL;
     60    #ifdef DEBUG
     61    if (paszEnv < (const char *)0x10000)
     62        kprintf(("ScanEnv: Invalid parameter paszEnv (%p)\n", paszEnv));
     63    #endif
     64
    4965    /*
    5066     * Loop thru the environment data until an empty string is reached.
    5167     */
     68    cchVar = strlen(pszVar);
    5269    while (*paszEnv != '\0')
    5370    {
    54         register int i;                 /* Variable use to store the compare result. */
    55 
    5671        /*
    57          * Variable name.
    58          * Check if it's matching the name we're searching for and skip the variable name.
     72         * Check if the variable name is it's matching the one we're searching for.
    5973         */
    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;
     74        const char *pszEqual = strchr(paszEnv, '=');
     75        if (pszEqual != NULL && (pszEqual - paszEnv) == cchVar
     76            && memcmp(paszEnv, pszVar, cchVar) == 0
     77            )
     78        {
     79            /*
     80             * Variable was found. Return pointer to the value.
     81             */
     82            return pszEqual + 1;
    6583        }
    6684
    6785        /*
    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.
     86         * Skip this variable. (Don't use pszEqual since it might be NULL)
    7187         */
    72         if (*paszEnv == '\0')
    73             break;
    74 
    75         /* Skip value */
    7688        paszEnv += strlen(paszEnv) + 1;
    7789    }
     
    8294
    8395/**
    84  * Get the linear pointer to the environment data.
     96 * Get the linear pointer to the environment data for the current
     97 * process or the process being started (EXECed).
    8598 *
    86  * @returns   Pointer to environment data.
    87  *            NULL on failure.
     99 * @param       fExecChild      TRUE:  Get exec child environment.
     100 *                                     (Not supported by method 2)
     101 *                              FALSE: Get current process environment.
     102 * @returns     Pointer to environment data.
     103 *              NULL on failure.
    88104 */
    89 const char *GetEnv(void)
     105const char *GetEnv(BOOL fExecChild)
    90106{
    91     /*  There is probably two ways of getting the environment data for a the
     107    /*  There are probably two ways of getting the environment data for the
    92108     *  current process: 1) get it from the PTDA->ptda_environ
    93109     *                   2) Local infosegment (LIS from GetDosVar devhlp)
    94      *  I am not sure which one of these works best. What I know is that
     110     *  I am not sure which one of these which works best. What I know is that
    95111     *  method 1) is used by the w_GetEnv API worker. This API is called at
    96112     *  Ring-0 from some delete file operation. (Which uses it to get the
     
    98114     *  I don't want to thunk around using that. There for I'll implement
    99115     *  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.
     116     *  2), testing will show which one of them are the better.
    101117     */
    102118
     
    116132     */
    117133    pPTDACur = ptdaGetCur();
    118     if (pPTDA != NULL)
     134    if (pPTDACur != NULL)
    119135    {
    120         pPTDA = ptdaGet_pPTDAExecChild(pPTDA);
    121         if (pPTDA != NULL)
     136        pPTDA = ptdaGet_pPTDAExecChild(pPTDACur);
     137        if (pPTDA != NULL && fExecChild)
    122138        {
    123139            hobEnviron = ptdaGet_ptda_environ(pPTDA);
     
    127143                if (rc == NO_ERROR)
    128144                    return (const char *)ulAddr;
    129                 kprintf(("GetEnv: VMObjHandleInfo failed with rc=%d for hob=0x%04x\n", rc, hobEnviron));
     145                kprintf(("GetEnv: (1) VMObjHandleInfo failed with rc=%d for hob=0x%04x \n", rc, hobEnviron));
    130146            }
    131147        }
     
    135151        {
    136152            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             }
     153            if (rc == NO_ERROR)
     154                return (const char *)ulAddr;
     155            kprintf(("GetEnv: (2) VMObjHandleInfo failed with rc=%d for hob=0x%04x\n", rc, hobEnviron));
    141156        }
    142157    }
    143158    else
    144     {
     159    {   /* Not called at task time? No current task! */
    145160        kprintf(("GetEnv: Failed to get current PTDA.\n"));
    146161    }
    147162
    148     return (const char *)ulAddr;
     163    return NULL;
     164
    149165
    150166    #else
     167
    151168
    152169    struct InfoSegLDT * pLIS;           /* Pointer to local infosegment. */
     
    162179    {
    163180        kprintf(("GetEnv: Failed to get local info segment\n"));
     181        NOREF(fExecChild);
    164182        return NULL;
    165183    }
Note: See TracChangeset for help on using the changeset viewer.