Changeset 4224 for trunk/src/kernel32/environ.cpp
- Timestamp:
- Sep 8, 2000, 8:07:52 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/environ.cpp
r4208 r4224 1 /* $Id: environ.cpp,v 1. 5 2000-09-07 21:40:28 phallerExp $ */1 /* $Id: environ.cpp,v 1.6 2000-09-08 18:07:49 sandervl Exp $ */ 2 2 3 3 /* … … 17 17 * 18 18 */ 19 20 /*****************************************************************************21 * Includes *22 *****************************************************************************/23 24 19 #include <odin.h> 25 20 #include <odinwrap.h> … … 38 33 #include "dbglocal.h" 39 34 40 /***************************************************************************** 41 * Defines * 42 *****************************************************************************/ 43 44 ODINDEBUGCHANNEL(KERNEL32-ENVIRONMENT) 45 46 47 //****************************************************************************** 48 //****************************************************************************** 49 ODINFUNCTION0(LPSTR, GetEnvironmentStringsA) 50 { 51 return (LPSTR) O32_GetEnvironmentStrings(); 52 } 53 //****************************************************************************** 54 //****************************************************************************** 55 ODINFUNCTION0(LPWSTR, GetEnvironmentStringsW) 35 //****************************************************************************** 36 //****************************************************************************** 37 LPSTR WIN32API GetEnvironmentStringsA(void) 38 { 39 dprintf(("KERNEL32: OS2GetEnvironmentStringsA\n")); 40 return (LPSTR) O32_GetEnvironmentStrings(); 41 } 42 //****************************************************************************** 43 //****************************************************************************** 44 LPWSTR WIN32API GetEnvironmentStringsW(VOID) 56 45 { 57 46 char *envstrings = (char *)O32_GetEnvironmentStrings(); … … 59 48 LPWSTR wenvstrings; 60 49 int len, i; 50 51 dprintf(("KERNEL32: GetEnvironmentStringsW\n")); 61 52 62 53 if(envstrings == NULL) … … 82 73 //****************************************************************************** 83 74 //****************************************************************************** 84 ODINFUNCTION1(BOOL, FreeEnvironmentStringsA, 85 LPSTR, envstrings) 86 { 87 dprintf(("not correctly implemented.\n")); 88 //free(envstrings); 75 BOOL WIN32API FreeEnvironmentStringsA(LPSTR envstrings) 76 { 77 dprintf(("KERNEL32: FreeEnvironmentStringsA\n")); 89 78 return(TRUE); 90 79 } 91 80 //****************************************************************************** 92 81 //****************************************************************************** 93 ODINFUNCTION1(BOOL, FreeEnvironmentStringsW, 94 LPWSTR, envstrings) 95 { 96 dprintf(("not correctly implemented.\n")); 97 //free(envstrings); 82 BOOL WIN32API FreeEnvironmentStringsW(LPWSTR envstrings) 83 { 84 dprintf(("KERNEL32: FreeEnvironmentStringsW\n")); 85 free(envstrings); 98 86 return(TRUE); 99 87 } 100 88 //****************************************************************************** 101 89 //****************************************************************************** 102 ODINFUNCTION2(BOOL, SetEnvironmentVariableA, 103 LPCSTR, lpszName, 104 LPCSTR, lpszValue) 105 { 106 return O32_SetEnvironmentVariable(lpszName, lpszValue); 107 } 108 //****************************************************************************** 109 //****************************************************************************** 110 ODINFUNCTION2(BOOL, SetEnvironmentVariableW, 111 LPCWSTR, lpszName, 112 LPCWSTR, lpszValue) 113 { 114 char *asciiname, *asciivalue; 115 BOOL rc; 116 117 asciiname = UnicodeToAsciiString((LPWSTR)lpszName); 118 asciivalue = UnicodeToAsciiString((LPWSTR)lpszValue); 119 rc = O32_SetEnvironmentVariable(asciiname, asciivalue); 120 FreeAsciiString(asciivalue); 121 FreeAsciiString(asciiname); 122 return(rc); 123 } 124 //****************************************************************************** 125 //****************************************************************************** 126 ODINFUNCTION3(DWORD, GetEnvironmentVariableA, 127 LPCSTR, lpName, 128 LPSTR, lpBuffer, 129 DWORD, nSize) 130 { 131 return O32_GetEnvironmentVariable(lpName, lpBuffer, nSize); 132 } 133 //****************************************************************************** 134 //****************************************************************************** 135 ODINFUNCTION3(DWORD, GetEnvironmentVariableW, 136 LPCWSTR, lpName, 137 LPWSTR, lpBuffer, 138 DWORD, nSize) 90 BOOL WIN32API SetEnvironmentVariableA(LPCSTR arg1, LPCSTR arg2) 91 { 92 dprintf(("KERNEL32: SetEnvironmentVariable %s to %s\n", arg1, arg2)); 93 return O32_SetEnvironmentVariable(arg1, arg2); 94 } 95 //****************************************************************************** 96 //****************************************************************************** 97 BOOL WIN32API SetEnvironmentVariableW(LPCWSTR lpName, LPCWSTR lpValue) 98 { 99 char *asciiname, *asciivalue; 100 BOOL rc; 101 102 dprintf(("KERNEL32: OS2SetEnvironmentVariableW\n")); 103 asciiname = UnicodeToAsciiString((LPWSTR)lpName); 104 asciivalue = UnicodeToAsciiString((LPWSTR)lpValue); 105 rc = O32_SetEnvironmentVariable(asciiname, asciivalue); 106 FreeAsciiString(asciivalue); 107 FreeAsciiString(asciiname); 108 return(rc); 109 } 110 //****************************************************************************** 111 //****************************************************************************** 112 DWORD WIN32API GetEnvironmentVariableA(LPCSTR arg1, LPSTR arg2, DWORD arg3) 113 { 114 dprintf(("KERNEL32: GetEnvironmentVariable %s\n", arg1)); 115 return O32_GetEnvironmentVariable(arg1, arg2, arg3); 116 } 117 //****************************************************************************** 118 //****************************************************************************** 119 DWORD WIN32API GetEnvironmentVariableW(LPCWSTR lpName, LPWSTR lpBuffer, 120 DWORD nSize) 139 121 { 140 122 char *astring, *asciibuffer; 141 123 DWORD rc; 142 124 143 asciibuffer = (char *)malloc(nSize+1); 144 *asciibuffer = 0; 145 astring = UnicodeToAsciiString((LPWSTR)lpName); 146 147 rc = O32_GetEnvironmentVariable(astring, asciibuffer, nSize); 148 AsciiToUnicode(asciibuffer, lpBuffer); 149 FreeAsciiString(astring); 150 free(asciibuffer); 151 return(rc); 125 dprintf(("KERNEL32: OS2GetEnvironmentVariableW\n")); 126 asciibuffer = (char *)malloc(nSize+1); 127 *asciibuffer = 0; 128 astring = UnicodeToAsciiString((LPWSTR)lpName); 129 130 rc = O32_GetEnvironmentVariable(astring, asciibuffer, nSize); 131 AsciiToUnicode(asciibuffer, lpBuffer); 132 FreeAsciiString(astring); 133 free(asciibuffer); 134 return(rc); 152 135 } 153 136 /*********************************************************************** … … 186 169 *****************************************************************************/ 187 170 188 ODINFUNCTION3(DWORD, ExpandEnvironmentStringsA, 189 LPCSTR, lpSrc, 190 LPSTR, lpDst, 191 DWORD, nSize) 171 DWORD WIN32API ExpandEnvironmentStringsA( LPCSTR src, LPSTR dst, DWORD count ) 192 172 { 193 173 DWORD len, total_size = 1; /* 1 for terminating '\0' */ 194 174 LPCSTR p, var; 195 175 196 if (!nSize) lpDst = NULL; 197 198 while (*lpSrc) 199 { 200 if (*lpSrc != '%') 176 dprintf(("KERNEL32:ExpandEnvironmentStringsA '%s', %08x, %08x", 177 src, dst, count 178 )); 179 180 if (!count) dst = NULL; 181 182 while (*src) 183 { 184 if (*src != '%') 201 185 { 202 if ((p = strchr( lpSrc, '%' ))) len = p - lpSrc;203 else len = strlen( lpSrc);204 var = lpSrc;205 lpSrc += len;186 if ((p = strchr( src, '%' ))) len = p - src; 187 else len = strlen(src); 188 var = src; 189 src += len; 206 190 } 207 191 else /* we are at the start of a variable */ 208 192 { 209 if ((p = strchr( lpSrc + 1, '%' )))193 if ((p = strchr( src + 1, '%' ))) 210 194 { 211 len = p - lpSrc - 1; /* Length of the variable name */195 len = p - src - 1; /* Length of the variable name */ 212 196 if ((var = ENV_FindVariable( GetEnvironmentStringsA(), 213 lpSrc + 1, len )))197 src + 1, len ))) 214 198 { 215 lpSrc += len + 2; /* Skip the variable name */199 src += len + 2; /* Skip the variable name */ 216 200 len = strlen(var); 217 201 } 218 202 else 219 203 { 220 var = lpSrc; /* Copy original name instead */204 var = src; /* Copy original name instead */ 221 205 len += 2; 222 lpSrc += len;206 src += len; 223 207 } 224 208 } 225 209 else /* unfinished variable name, ignore it */ 226 210 { 227 var = lpSrc;228 len = strlen( lpSrc); /* Copy whole string */229 lpSrc += len;211 var = src; 212 len = strlen(src); /* Copy whole string */ 213 src += len; 230 214 } 231 215 } 232 216 total_size += len; 233 if ( lpDst)217 if (dst) 234 218 { 235 if ( nSize < len) len = nSize;236 memcpy( lpDst, var, len );237 lpDst += len;238 nSize-= len;219 if (count < len) len = count; 220 memcpy( dst, var, len ); 221 dst += len; 222 count -= len; 239 223 } 240 224 } 241 225 242 226 /* Null-terminate the string */ 243 if ( lpDst)244 { 245 if (! nSize) lpDst--;246 * lpDst = '\0';227 if (dst) 228 { 229 if (!count) dst--; 230 *dst = '\0'; 247 231 } 248 232 dprintf(("KERNEL32:ExpandEnvironmentStringsA returned %s %d", 249 lpDst, total_size));233 dst, total_size)); 250 234 return total_size; 251 235 } … … 270 254 *****************************************************************************/ 271 255 272 ODINFUNCTION3(DWORD, ExpandEnvironmentStringsW, 273 LPCWSTR,lpSrc, 274 LPWSTR, lpDst, 275 DWORD, nSize) 256 DWORD WIN32API ExpandEnvironmentStringsW(LPCWSTR lpSrc, LPWSTR lpDst, DWORD nSize) 276 257 { 277 258 LPSTR srcA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpSrc ); 278 259 LPSTR dstA = lpDst ? (LPSTR)HeapAlloc( GetProcessHeap(), 0, nSize ) : NULL; 279 260 261 dprintf(("KERNEL32:ExpandEnvironmentStringsW(%08x,%08x,%08x)", lpSrc, lpDst, nSize)); 262 280 263 DWORD ret = ExpandEnvironmentStringsA( srcA, dstA, nSize ); 281 264 if (dstA)
Note:
See TracChangeset
for help on using the changeset viewer.