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