Changeset 28912 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Apr 29, 2010 4:50:25 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 60860
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r28903 r28912 492 492 493 493 RuntimeR3_SOURCES.linux = \ 494 generic/pathhost-generic.cpp \495 494 generic/RTDirQueryInfo-generic.cpp \ 496 495 generic/RTDirSetTimes-generic.cpp \ … … 522 521 r3/posix/ldrNative-posix.cpp \ 523 522 r3/posix/path-posix.cpp \ 523 r3/posix/pathhost-posix.cpp \ 524 524 r3/posix/pipe-posix.cpp \ 525 525 r3/posix/poll-posix.cpp \ … … 557 557 558 558 RuntimeR3_SOURCES.os2 = \ 559 generic/pathhost-generic.cpp \560 559 generic/RTDirQueryInfo-generic.cpp \ 561 560 generic/RTDirSetTimes-generic.cpp \ … … 601 600 r3/posix/ldrNative-posix.cpp \ 602 601 r3/posix/path-posix.cpp \ 602 r3/posix/pathhost-posix.cpp \ 603 603 r3/posix/process-posix.cpp \ 604 604 r3/posix/RTTimeNow-posix.cpp \ … … 658 658 ## @todo Make BSD sched, implement RTMP*. 659 659 RuntimeR3_SOURCES.freebsd = \ 660 generic/pathhost-generic.cpp \661 660 generic/RTDirQueryInfo-generic.cpp \ 662 661 generic/RTDirSetTimes-generic.cpp \ … … 694 693 r3/posix/ldrNative-posix.cpp \ 695 694 r3/posix/path-posix.cpp \ 695 r3/posix/pathhost-posix.cpp \ 696 696 r3/posix/pipe-posix.cpp \ 697 697 r3/posix/poll-posix.cpp \ … … 713 713 714 714 RuntimeR3_SOURCES.solaris = \ 715 generic/pathhost-generic.cpp \716 715 generic/RTDirQueryInfo-generic.cpp \ 717 716 generic/RTDirSetTimes-generic.cpp \ … … 736 735 r3/posix/ldrNative-posix.cpp \ 737 736 r3/posix/path-posix.cpp \ 737 r3/posix/pathhost-posix.cpp \ 738 738 r3/posix/pipe-posix.cpp \ 739 739 r3/posix/poll-posix.cpp \ -
trunk/src/VBox/Runtime/generic/pathhost-generic.cpp
r28910 r28912 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Path Convertions, generic .3 * IPRT - Path Convertions, generic pass through. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 32 32 #include "internal/iprt.h" 33 33 #include "internal/path.h" 34 #include "internal/thread.h"35 34 36 #include <iprt/ env.h>35 #include <iprt/assert.h> 37 36 #include <iprt/string.h> 38 #include <iprt/once.h>39 40 41 /*******************************************************************************42 * Global Variables *43 *******************************************************************************/44 /** Initialize once object. */45 static RTONCE g_OnceInitPathConv = RTONCE_INITIALIZER;46 /** If set, then we can pass UTF-8 thru directly. */47 static bool g_fPassthruUtf8 = false;48 /** The UTF-8 to FS iconv cache entry. */49 static RTSTRICONV g_enmUtf8ToFsIdx = RTSTRICONV_UTF8_TO_LOCALE;50 /** The FS to UTF-8 iconv cache entry. */51 static RTSTRICONV g_enmFsToUtf8Idx = RTSTRICONV_LOCALE_TO_UTF8;52 /** The codeset we're using. */53 static char g_szFsCodeset[32];54 55 56 /**57 * Do a case insensitive compare where the 2nd string is known and can be case58 * folded when writing the code.59 *60 * @returns see strcmp.61 * @param pszStr1 The string to compare against pszLower and62 * pszUpper.63 * @param pszUpper The upper case edition of the 2nd string.64 * @param pszLower The lower case edition of the 2nd string.65 */66 static int rtPathStrICmp(const char *pszStr1, const char *pszUpper, const char *pszLower)67 {68 Assert(strlen(pszLower) == strlen(pszUpper));69 for (;;)70 {71 char ch1 = *pszStr1++;72 char ch2Upper = *pszUpper++;73 char ch2Lower = *pszLower++;74 if ( ch1 != ch2Upper75 && ch1 != ch2Lower)76 return ch1 < ch2Upper ? -1 : 1;77 if (!ch1)78 return 0;79 }80 }81 82 /**83 * Is the specified codeset something we can treat as UTF-8.84 *85 * @returns true if we can do UTF-8 passthru, false if not.86 * @param pszCodeset The codeset in question.87 */88 static bool rtPathConvInitIsUtf8(const char *pszCodeset)89 {90 /* Paranoia. */91 if (!pszCodeset)92 return false;93 94 /*95 * Avoid RTStrICmp at this point.96 */97 static struct98 {99 const char *pszUpper;100 const char *pszLower;101 } const s_aUtf8Compatible[] =102 {103 /* The default locale. */104 { "C" , "c" },105 { "POSIX" , "posix" },106 /* 7-bit ASCII. */107 { "ANSI_X3.4-1968" , "ansi_x3.4-1968" },108 { "ANSI_X3.4-1986" , "ansi_x3.4-1986" },109 { "US-ASCII" , "us-ascii" },110 { "ISO646-US" , "iso646-us" },111 { "ISO_646.IRV:1991" , "iso_646.irv:1991" },112 { "ISO-IR-6" , "iso-ir-6" },113 { "IBM367" , "ibm367" },114 /* UTF-8 */115 { "UTF-8" , "utf-8" },116 { "UTF8" , "utf8" },117 { "ISO-10646/UTF-8" , "iso-10646/utf-8" },118 { "ISO-10646/UTF8" , "iso-10646/utf8" }119 };120 121 for (size_t i = 0; i < RT_ELEMENTS(s_aUtf8Compatible); i++)122 if (!rtPathStrICmp(pszCodeset, s_aUtf8Compatible[i].pszUpper, s_aUtf8Compatible[i].pszLower))123 return true;124 125 return false;126 }127 128 129 /**130 * Init once for the path conversion code.131 *132 * @returns IPRT status code.133 * @param pvUser1 Unused.134 * @param pvUser2 Unused.135 */136 static DECLCALLBACK(int32_t) rtPathConvInitOnce(void *pvUser1, void *pvUser2)137 {138 /*139 * Read the environment variable, no mercy on misconfigs here except that140 * empty values are quietly ignored. (We use a temp buffer for stripping.)141 */142 char *pszEnvValue = NULL;143 char szEnvValue[sizeof(g_szFsCodeset)];144 int rc = RTEnvGetEx(RTENV_DEFAULT, RTPATH_CODESET_ENV_VAR, szEnvValue, sizeof(szEnvValue), NULL);145 if (rc != VERR_ENV_VAR_NOT_FOUND && RT_FAILURE(rc))146 return rc;147 if (RT_SUCCESS(rc))148 pszEnvValue = RTStrStrip(szEnvValue);149 150 if (pszEnvValue && *pszEnvValue)151 {152 g_fPassthruUtf8 = rtPathConvInitIsUtf8(pszEnvValue);153 g_enmFsToUtf8Idx = RTSTRICONV_FS_TO_UTF8;154 g_enmUtf8ToFsIdx = RTSTRICONV_UTF8_TO_FS;155 strcpy(g_szFsCodeset, pszEnvValue);156 }157 else158 {159 const char *pszCodeset = rtStrGetLocaleCodeset();160 size_t cchCodeset = pszCodeset ? strlen(pszCodeset) : sizeof(g_szFsCodeset);161 if (cchCodeset >= sizeof(g_szFsCodeset))162 /* This shouldn't happen, but we'll manage. */163 g_szFsCodeset[0] = '\0';164 else165 {166 memcpy(g_szFsCodeset, pszCodeset, cchCodeset + 1);167 pszCodeset = g_szFsCodeset;168 }169 g_fPassthruUtf8 = rtPathConvInitIsUtf8(pszCodeset);170 g_enmFsToUtf8Idx = RTSTRICONV_LOCALE_TO_UTF8;171 g_enmUtf8ToFsIdx = RTSTRICONV_UTF8_TO_LOCALE;172 }173 174 NOREF(pvUser1); NOREF(pvUser2);175 return VINF_SUCCESS;176 }177 37 178 38 179 39 int rtPathToNative(char **ppszNativePath, const char *pszPath) 180 40 { 181 *ppszNativePath = NULL; 182 183 int rc = RTOnce(&g_OnceInitPathConv, rtPathConvInitOnce, NULL, NULL); 184 if (RT_SUCCESS(rc)) 185 { 186 if (g_fPassthruUtf8 || !*pszPath) 187 *ppszNativePath = (char *)pszPath; 188 else 189 rc = rtStrConvert(pszPath, strlen(pszPath), "UTF-8", 190 ppszNativePath, 0, g_szFsCodeset, 191 2, g_enmUtf8ToFsIdx); 192 } 193 return rc; 41 *ppszNativePath = (char *)pszPath; 42 return VINF_SUCCESS; 194 43 } 195 44 … … 205 54 void rtPathFreeNative(char *pszNativePath, const char *pszPath) 206 55 { 207 if ( pszNativePath != pszPath 208 && pszNativePath) 209 RTStrFree(pszNativePath); 56 Assert(pszNativePath == pszPath || !pszNativePath); 57 NOREF(pszNativePath); NOREF(pszPath); 210 58 } 211 59 … … 213 61 int rtPathFromNative(char **ppszPath, const char *pszNativePath) 214 62 { 215 *ppszPath = NULL; 216 217 int rc = RTOnce(&g_OnceInitPathConv, rtPathConvInitOnce, NULL, NULL); 63 int rc = RTStrValidateEncodingEx(pszNativePath, RTSTR_MAX, 0 /*fFlags*/); 218 64 if (RT_SUCCESS(rc)) 219 { 220 if (g_fPassthruUtf8 || !*pszNativePath) 221 { 222 size_t cCpsIgnored; 223 size_t cchNativePath; 224 rc = rtUtf8Length(pszNativePath, RTSTR_MAX, &cCpsIgnored, &cchNativePath); 225 if (RT_SUCCESS(rc)) 226 { 227 char *pszPath; 228 *ppszPath = pszPath = RTStrAlloc(cchNativePath + 1); 229 if (pszPath) 230 memcpy(pszPath, pszNativePath, cchNativePath + 1); 231 else 232 rc = VERR_NO_STR_MEMORY; 233 } 234 } 235 else 236 rc = rtStrConvert(pszNativePath, strlen(pszNativePath), g_szFsCodeset, 237 ppszPath, 0, "UTF-8", 238 2, g_enmFsToUtf8Idx); 239 } 65 rc = RTStrDupEx(ppszPath, pszNativePath); 240 66 return rc; 241 67 } -
trunk/src/VBox/Runtime/r3/posix/pathhost-posix.cpp
r28910 r28912 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Path Convertions, generic.3 * IPRT - Path Convertions, POSIX. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as
Note:
See TracChangeset
for help on using the changeset viewer.