vbox的更動 27346 路徑 trunk/src/VBox/Runtime/generic
- 時間撮記:
- 2010-3-14 下午06:35:19 (15 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/generic/env-generic.cpp
r25000 r27346 40 40 #include <iprt/alloca.h> 41 41 #include <iprt/string.h> 42 #include <iprt/sort.h> 42 43 #include <iprt/err.h> 43 44 #include "internal/magics.h" … … 667 668 } 668 669 RT_EXPORT_SYMBOL(RTEnvGetExecEnvP); 670 671 672 /** 673 * RTSort callback for comparing two environment varibles. 674 * 675 * @returns -1, 0, 1. See PFNRTSORTCMP. 676 * @param pvElement1 Variable 1. 677 * @param pvElement2 Variable 2. 678 * @param pvUser Ignored. 679 */ 680 DECLCALLBACK(int) rtEnvSortCompare(const void *pvElement1, const void *pvElement2, void *pvUser) 681 { 682 NOREF(pvUser); 683 int iDiff = strcmp((const char *)pvElement1, (const char *)pvElement2); 684 if (iDiff < 0) 685 iDiff = -1; 686 else if (iDiff > 0) 687 iDiff = 1; 688 return iDiff; 689 } 690 691 692 RTDECL(int) RTEnvQueryUtf16Block(RTENV hEnv, PRTUTF16 *ppwszzBlock) 693 { 694 RTENV hClone = NIL_RTENV; 695 PRTENVINTERNAL pIntEnv; 696 int rc; 697 698 /* 699 * Validate / simplify input. 700 */ 701 if (hEnv == RTENV_DEFAULT) 702 { 703 rc = RTEnvClone(&hClone, RTENV_DEFAULT); 704 if (RT_FAILURE(rc)) 705 return rc; 706 pIntEnv = hClone; 707 } 708 else 709 { 710 pIntEnv = hEnv; 711 AssertPtrReturn(pIntEnv, VERR_INVALID_HANDLE); 712 AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, VERR_INVALID_HANDLE); 713 } 714 715 RTENV_LOCK(pIntEnv); 716 717 /* 718 * Sort it first. 719 */ 720 RTSortApvShell((void **)pIntEnv->papszEnv, pIntEnv->cVars, rtEnvSortCompare, pIntEnv); 721 722 /* 723 * Calculate the size. 724 */ 725 size_t cwc; 726 size_t cwcTotal = 2; 727 for (size_t iVar = 0; iVar < pIntEnv->cVars; iVar++) 728 { 729 rc = RTStrCalcUtf16LenEx(pIntEnv->papszEnv[iVar], RTSTR_MAX, &cwc); 730 AssertRCBreak(rc); 731 cwcTotal += cwc + 1; 732 } 733 734 PRTUTF16 pwszzBlock = NULL; 735 if (RT_SUCCESS(rc)) 736 { 737 /* 738 * Perform the conversion. 739 */ 740 PRTUTF16 pwszz = pwszzBlock = (PRTUTF16)RTMemAlloc(cwcTotal * sizeof(RTUTF16)); 741 if (pwszz) 742 { 743 size_t cwcLeft = cwcTotal; 744 for (size_t iVar = 0; iVar < pIntEnv->cVars; iVar++) 745 { 746 rc = RTStrToUtf16Ex(pIntEnv->papszEnv[iVar], RTSTR_MAX, 747 &pwszz, cwcTotal - (pwszz - pwszzBlock), &cwc); 748 AssertRCBreak(rc); 749 pwszz += cwc + 1; 750 cwcLeft -= cwc + 1; 751 AssertBreakStmt(cwcLeft >= 2, rc = VERR_INTERNAL_ERROR_3); 752 } 753 AssertStmt(cwcLeft == 2 || RT_FAILURE(rc), rc = VERR_INTERNAL_ERROR_2); 754 if (RT_SUCCESS(rc)) 755 { 756 pwszz[0] = '\0'; 757 pwszz[1] = '\0'; 758 } 759 else 760 { 761 RTMemFree(pwszzBlock); 762 pwszzBlock = NULL; 763 } 764 } 765 else 766 rc = VERR_NO_MEMORY; 767 } 768 769 RTENV_UNLOCK(pIntEnv); 770 771 if (hClone != NIL_RTENV) 772 RTEnvDestroy(hClone); 773 if (RT_SUCCESS(rc)) 774 *ppwszzBlock = pwszzBlock; 775 return rc; 776 } 777 RT_EXPORT_SYMBOL(RTEnvGetExecEnvP); 778 779 780 RTDECL(void) RTEnvFreeUtf16Block(PRTUTF16 pwszzBlock) 781 { 782 RTMemFree(pwszzBlock); 783 } 784 RT_EXPORT_SYMBOL(RTEnvFreeUtf16Block); 785
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器