VirtualBox

Changeset 28912 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Apr 29, 2010 4:50:25 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
60860
Message:

generic/pathhost-generic.cpp -> r3/posix/pathhost-posix.cpp; rewrote pathhost-generic.cpp as a UTF-8 pass through.

Location:
trunk/src/VBox/Runtime
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r28903 r28912  
    492492
    493493RuntimeR3_SOURCES.linux = \
    494         generic/pathhost-generic.cpp \
    495494        generic/RTDirQueryInfo-generic.cpp \
    496495        generic/RTDirSetTimes-generic.cpp \
     
    522521        r3/posix/ldrNative-posix.cpp \
    523522        r3/posix/path-posix.cpp \
     523        r3/posix/pathhost-posix.cpp \
    524524        r3/posix/pipe-posix.cpp \
    525525        r3/posix/poll-posix.cpp \
     
    557557
    558558RuntimeR3_SOURCES.os2   = \
    559         generic/pathhost-generic.cpp \
    560559        generic/RTDirQueryInfo-generic.cpp \
    561560        generic/RTDirSetTimes-generic.cpp \
     
    601600        r3/posix/ldrNative-posix.cpp \
    602601        r3/posix/path-posix.cpp \
     602        r3/posix/pathhost-posix.cpp \
    603603        r3/posix/process-posix.cpp \
    604604        r3/posix/RTTimeNow-posix.cpp \
     
    658658## @todo Make BSD sched, implement RTMP*.
    659659RuntimeR3_SOURCES.freebsd = \
    660         generic/pathhost-generic.cpp \
    661660        generic/RTDirQueryInfo-generic.cpp \
    662661        generic/RTDirSetTimes-generic.cpp \
     
    694693        r3/posix/ldrNative-posix.cpp \
    695694        r3/posix/path-posix.cpp \
     695        r3/posix/pathhost-posix.cpp \
    696696        r3/posix/pipe-posix.cpp \
    697697        r3/posix/poll-posix.cpp \
     
    713713
    714714RuntimeR3_SOURCES.solaris = \
    715         generic/pathhost-generic.cpp \
    716715        generic/RTDirQueryInfo-generic.cpp \
    717716        generic/RTDirSetTimes-generic.cpp \
     
    736735        r3/posix/ldrNative-posix.cpp \
    737736        r3/posix/path-posix.cpp \
     737        r3/posix/pathhost-posix.cpp \
    738738        r3/posix/pipe-posix.cpp \
    739739        r3/posix/poll-posix.cpp \
  • trunk/src/VBox/Runtime/generic/pathhost-generic.cpp

    r28910 r28912  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Path Convertions, generic.
     3 * IPRT - Path Convertions, generic pass through.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232#include "internal/iprt.h"
    3333#include "internal/path.h"
    34 #include "internal/thread.h"
    3534
    36 #include <iprt/env.h>
     35#include <iprt/assert.h>
    3736#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 case
    58  * folded when writing the code.
    59  *
    60  * @returns see strcmp.
    61  * @param   pszStr1             The string to compare against pszLower and
    62  *                              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 != ch2Upper
    75             && 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 struct
    98     {
    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 that
    140      * 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     else
    158     {
    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         else
    165         {
    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 }
    17737
    17838
    17939int rtPathToNative(char **ppszNativePath, const char *pszPath)
    18040{
    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;
    19443}
    19544
     
    20554void rtPathFreeNative(char *pszNativePath, const char *pszPath)
    20655{
    207     if (    pszNativePath != pszPath
    208         &&  pszNativePath)
    209         RTStrFree(pszNativePath);
     56    Assert(pszNativePath == pszPath || !pszNativePath);
     57    NOREF(pszNativePath); NOREF(pszPath);
    21058}
    21159
     
    21361int rtPathFromNative(char **ppszPath, const char *pszNativePath)
    21462{
    215     *ppszPath = NULL;
    216 
    217     int rc = RTOnce(&g_OnceInitPathConv, rtPathConvInitOnce, NULL, NULL);
     63    int rc = RTStrValidateEncodingEx(pszNativePath, RTSTR_MAX, 0 /*fFlags*/);
    21864    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);
    24066    return rc;
    24167}
  • trunk/src/VBox/Runtime/r3/posix/pathhost-posix.cpp

    r28910 r28912  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Path Convertions, generic.
     3 * IPRT - Path Convertions, POSIX.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette