- 時間撮記:
- 2014-2-11 上午02:21:39 (11 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/generic/env-generic.cpp
r46035 r50408 57 57 * Defined Constants And Macros * 58 58 *******************************************************************************/ 59 /** The allocation granularity of the RTENVINTERNAL::papszEnv memory. */ 60 #define RTENV_GROW_SIZE 16 61 59 62 /** Macro that unlocks the specified environment block. */ 60 63 #define RTENV_LOCK(pEnvInt) do { } while (0) 61 64 /** Macro that unlocks the specified environment block. */ 62 65 #define RTENV_UNLOCK(pEnvInt) do { } while (0) 66 67 /** @def RTENV_HAVE_WENVIRON 68 * Indicates that we have a _wenviron variable with UTF-16 strings that we 69 * better use instead of the current-cp strings in environ. */ 70 #if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING) 71 # define RTENV_HAVE_WENVIRON 1 72 #endif 73 74 /** @def RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API 75 * Indicates the RTEnv*Utf8 APIs are implemented. */ 76 #if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING) 77 # define RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API 1 78 #endif 63 79 64 80 … … 85 101 * This get (re-)constructed when RTEnvGetExecEnvP method is called. */ 86 102 char **papszEnvOtherCP; 103 104 /** The compare function we're using. */ 105 DECLCALLBACKMEMBER(int, pfnCompare)(const char *psz1, const char *psz2, size_t cchMax); 87 106 } RTENVINTERNAL, *PRTENVINTERNAL; 88 89 /** The allocation granularity of the RTENVINTERNAL::papszEnv memory. */90 #define RTENV_GROW_SIZE 1691 107 92 108 … … 112 128 * 113 129 * @returns IPRT status code. 114 * @param ppIntEnv Where to store the result. 115 * @param cAllocated The initial array size. 130 * @param ppIntEnv Where to store the result. 131 * @param cAllocated The initial array size. 132 * @param fCaseSensitive Whether the environment block is case sensitive or 133 * not. 116 134 */ 117 static int rtEnvCreate(PRTENVINTERNAL *ppIntEnv, size_t cAllocated )135 static int rtEnvCreate(PRTENVINTERNAL *ppIntEnv, size_t cAllocated, bool fCaseSensitive) 118 136 { 119 137 /* … … 127 145 */ 128 146 pIntEnv->u32Magic = RTENV_MAGIC; 147 pIntEnv->pfnCompare = fCaseSensitive ? RTStrNCmp : RTStrNICmp; 129 148 pIntEnv->papszEnvOtherCP = NULL; 130 149 pIntEnv->cVars = 0; … … 147 166 { 148 167 AssertPtrReturn(pEnv, VERR_INVALID_POINTER); 149 return rtEnvCreate(pEnv, RTENV_GROW_SIZE );168 return rtEnvCreate(pEnv, RTENV_GROW_SIZE, false /*fCaseSensitive*/); 150 169 } 151 170 RT_EXPORT_SYMBOL(RTEnvCreate); … … 201 220 * Validate input and figure out how many variable to clone and where to get them. 202 221 */ 222 bool fCaseSensitive = true; 203 223 size_t cVars; 204 224 const char * const *papszEnv; 225 #ifdef RTENV_HAVE_WENVIRON 226 PCRTUTF16 const * papwszEnv; 227 #endif 205 228 PRTENVINTERNAL pIntEnvToClone; 206 229 AssertPtrReturn(pEnv, VERR_INVALID_POINTER); 207 230 if (EnvToClone == RTENV_DEFAULT) 208 231 { 232 cVars = 0; 209 233 pIntEnvToClone = NULL; 234 #ifdef RTENV_HAVE_WENVIRON 235 papszEnv = NULL; 236 papwszEnv = (PCRTUTF16 * const )_wenviron; 237 if (papwszEnv) 238 while (papwszEnv[cVars]) 239 cVars++; 240 #else 210 241 papszEnv = rtEnvDefault(); 211 cVars = 0;212 242 if (papszEnv) 213 243 while (papszEnv[cVars]) 214 244 cVars++; 245 #endif 246 247 #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) 248 /* DOS systems was case insensitive. A prime example is the 'Path' 249 variable on windows which turns into the 'PATH' variable. */ 250 fCaseSensitive = false; 251 #endif 215 252 } 216 253 else … … 229 266 */ 230 267 PRTENVINTERNAL pIntEnv; 231 int rc = rtEnvCreate(&pIntEnv, cVars + 1 /* NULL */ );268 int rc = rtEnvCreate(&pIntEnv, cVars + 1 /* NULL */, fCaseSensitive); 232 269 if (RT_SUCCESS(rc)) 233 270 { … … 240 277 for (size_t iSrc = 0; iSrc < cVars; iSrc++) 241 278 { 279 #ifdef RTENV_HAVE_WENVIRON 280 int rc2 = RTUtf16ToUtf8(papwszEnv[iSrc], &pIntEnv->papszEnv[iDst]); 281 #else 242 282 int rc2 = RTStrCurrentCPToUtf8(&pIntEnv->papszEnv[iDst], papszEnv[iSrc]); 283 #endif 243 284 if (RT_SUCCESS(rc2)) 244 285 iDst++; … … 319 360 if (Env == RTENV_DEFAULT) 320 361 { 362 #ifdef RT_OS_WINDOWS 363 rc = RTEnvSetUtf8(pszVar, pszValue); 364 #else 321 365 /* 322 366 * Since RTEnvPut isn't UTF-8 clean and actually expects the strings … … 337 381 RTStrFree(pszVarOtherCP); 338 382 } 383 #endif 339 384 } 340 385 else … … 364 409 size_t iVar; 365 410 for (iVar = 0; iVar < pIntEnv->cVars; iVar++) 366 if ( ! strncmp(pIntEnv->papszEnv[iVar], pszVar, cchVar)411 if ( !pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar) 367 412 && pIntEnv->papszEnv[iVar][cchVar] == '=') 368 413 break; … … 424 469 if (Env == RTENV_DEFAULT) 425 470 { 471 #ifdef RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API 472 rc = RTEnvUnsetUtf8(pszVar); 473 #else 426 474 /* 427 475 * Since RTEnvUnset isn't UTF-8 clean and actually expects the strings … … 436 484 RTStrFree(pszVarOtherCP); 437 485 } 486 #endif 438 487 } 439 488 else … … 452 501 size_t iVar; 453 502 for (iVar = 0; iVar < pIntEnv->cVars; iVar++) 454 if ( ! strncmp(pIntEnv->papszEnv[iVar], pszVar, cchVar)503 if ( !pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar) 455 504 && pIntEnv->papszEnv[iVar][cchVar] == '=') 456 505 { … … 484 533 if (Env == RTENV_DEFAULT) 485 534 { 535 #ifdef RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API 536 rc = RTEnvGetUtf8(pszVar, pszValue, cbValue, pcchActual); 537 #else 486 538 /* 487 539 * Since RTEnvGet isn't UTF-8 clean and actually expects the strings … … 518 570 rc = VERR_ENV_VAR_NOT_FOUND; 519 571 } 572 #endif 520 573 } 521 574 else … … 534 587 size_t iVar; 535 588 for (iVar = 0; iVar < pIntEnv->cVars; iVar++) 536 if ( ! strncmp(pIntEnv->papszEnv[iVar], pszVar, cchVar)589 if ( !pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar) 537 590 && pIntEnv->papszEnv[iVar][cchVar] == '=') 538 591 { … … 555 608 } 556 609 return rc; 557 558 610 } 559 611 RT_EXPORT_SYMBOL(RTEnvGetEx); … … 564 616 AssertPtrReturn(pszVar, false); 565 617 566 bool fExist = false;618 bool fExists = false; 567 619 if (Env == RTENV_DEFAULT) 568 620 { 621 #ifdef RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API 622 fExists = RTEnvExistsUtf8(pszVar); 623 #else 569 624 /* 570 625 * Since RTEnvExist isn't UTF-8 clean and actually expects the strings … … 576 631 if (RT_SUCCESS(rc)) 577 632 { 578 fExist = RTEnvExist(pszVarOtherCP);633 fExists = RTEnvExist(pszVarOtherCP); 579 634 RTStrFree(pszVarOtherCP); 580 635 } 636 #endif 581 637 } 582 638 else … … 593 649 const size_t cchVar = strlen(pszVar); 594 650 for (size_t iVar = 0; iVar < pIntEnv->cVars; iVar++) 595 if ( ! strncmp(pIntEnv->papszEnv[iVar], pszVar, cchVar)651 if ( !pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar) 596 652 && pIntEnv->papszEnv[iVar][cchVar] == '=') 597 653 { 598 fExist = true;654 fExists = true; 599 655 break; 600 656 } … … 602 658 RTENV_UNLOCK(pIntEnv); 603 659 } 604 return fExist ;660 return fExists; 605 661 } 606 662 RT_EXPORT_SYMBOL(RTEnvExistEx); … … 612 668 if (Env == RTENV_DEFAULT) 613 669 { 670 /** @todo fix this API it's fundamentally wrong! */ 614 671 papszRet = rtEnvDefault(); 615 672 if (!papszRet)
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器