Changeset 4164 for trunk/src/win32k/misc/env.c
- Timestamp:
- Sep 2, 2000, 11:08:23 PM (25 years ago)
- 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:04bird Exp $1 /* $Id: env.c,v 1.3 2000-09-02 21:08:13 bird Exp $ 2 2 * 3 3 * Environment access functions … … 14 14 #define INCL_DOSERRORS /* Error codes */ 15 15 #define INCL_OS2KRNL_VM /* OS2KRNL: Virtual Memory Management */ 16 16 #define INCL_OS2KRNL_PTDA /* OS2KNRL: (per)ProcessTaskDataArea */ 17 17 18 18 /******************************************************************************* … … 21 21 #include <os2.h> 22 22 23 #include "devSegDf.h" /* Win32k segment definitions. */ 23 24 #include "dev32.h" 24 25 #include "dev32hlp.h" 25 26 #include "log.h" 26 #include "ptda.h"27 27 #include "OS2Krnl.h" 28 28 #include <string.h> 29 29 #include "macros.h" 30 30 #include "env.h" 31 31 … … 39 39 * @param paszEnv Pointer to the environment data to search. 40 40 * 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.) 46 47 */ 47 48 const char *ScanEnv(const char *paszEnv, const char *pszVar) 48 49 { 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 49 65 /* 50 66 * Loop thru the environment data until an empty string is reached. 51 67 */ 68 cchVar = strlen(pszVar); 52 69 while (*paszEnv != '\0') 53 70 { 54 register int i; /* Variable use to store the compare result. */55 56 71 /* 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. 59 73 */ 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; 65 83 } 66 84 67 85 /* 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) 71 87 */ 72 if (*paszEnv == '\0')73 break;74 75 /* Skip value */76 88 paszEnv += strlen(paszEnv) + 1; 77 89 } … … 82 94 83 95 /** 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). 85 98 * 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. 88 104 */ 89 const char *GetEnv( void)105 const char *GetEnv(BOOL fExecChild) 90 106 { 91 /* There is probably two ways of getting the environment data for athe107 /* There are probably two ways of getting the environment data for the 92 108 * current process: 1) get it from the PTDA->ptda_environ 93 109 * 2) Local infosegment (LIS from GetDosVar devhlp) 94 * I am not sure which one of these w orks best. What I know is that110 * I am not sure which one of these which works best. What I know is that 95 111 * method 1) is used by the w_GetEnv API worker. This API is called at 96 112 * Ring-0 from some delete file operation. (Which uses it to get the … … 98 114 * I don't want to thunk around using that. There for I'll implement 99 115 * 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. 101 117 */ 102 118 … … 116 132 */ 117 133 pPTDACur = ptdaGetCur(); 118 if (pPTDA != NULL)134 if (pPTDACur != NULL) 119 135 { 120 pPTDA = ptdaGet_pPTDAExecChild(pPTDA );121 if (pPTDA != NULL )136 pPTDA = ptdaGet_pPTDAExecChild(pPTDACur); 137 if (pPTDA != NULL && fExecChild) 122 138 { 123 139 hobEnviron = ptdaGet_ptda_environ(pPTDA); … … 127 143 if (rc == NO_ERROR) 128 144 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)); 130 146 } 131 147 } … … 135 151 { 136 152 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)); 141 156 } 142 157 } 143 158 else 144 { 159 { /* Not called at task time? No current task! */ 145 160 kprintf(("GetEnv: Failed to get current PTDA.\n")); 146 161 } 147 162 148 return (const char *)ulAddr; 163 return NULL; 164 149 165 150 166 #else 167 151 168 152 169 struct InfoSegLDT * pLIS; /* Pointer to local infosegment. */ … … 162 179 { 163 180 kprintf(("GetEnv: Failed to get local info segment\n")); 181 NOREF(fExecChild); 164 182 return NULL; 165 183 }
Note:
See TracChangeset
for help on using the changeset viewer.