pathhost-posix.cpp revision c58f1213e628a545081c70e26c6b67a841cff880
/* $Id$ */
/** @file
* IPRT - Path Conversions, POSIX.
*/
/*
* Copyright (C) 2006-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_PATH
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Initialize once object. */
/** If set, then we can pass UTF-8 thru directly. */
static bool g_fPassthruUtf8 = false;
/** The UTF-8 to FS iconv cache entry. */
/** The FS to UTF-8 iconv cache entry. */
/** The codeset we're using. */
static char g_szFsCodeset[32];
/**
* Do a case insensitive compare where the 2nd string is known and can be case
* folded when writing the code.
*
* @returns see strcmp.
* @param pszStr1 The string to compare against pszLower and
* pszUpper.
* @param pszUpper The upper case edition of the 2nd string.
* @param pszLower The lower case edition of the 2nd string.
*/
{
for (;;)
{
if (!ch1)
return 0;
}
}
/**
* Is the specified codeset something we can treat as UTF-8.
*
* @returns true if we can do UTF-8 passthru, false if not.
* @param pszCodeset The codeset in question.
*/
static bool rtPathConvInitIsUtf8(const char *pszCodeset)
{
/* Paranoia. */
if (!pszCodeset)
return false;
/*
* Avoid RTStrICmp at this point.
*/
static struct
{
const char *pszUpper;
const char *pszLower;
} const s_aUtf8Compatible[] =
{
/* The default locale. */
{ "C" , "c" },
{ "POSIX" , "posix" },
/* 7-bit ASCII. */
{ "ANSI_X3.4-1968" , "ansi_x3.4-1968" },
{ "ANSI_X3.4-1986" , "ansi_x3.4-1986" },
{ "US-ASCII" , "us-ascii" },
{ "ISO646-US" , "iso646-us" },
{ "ISO_646.IRV:1991" , "iso_646.irv:1991" },
{ "ISO-IR-6" , "iso-ir-6" },
{ "IBM367" , "ibm367" },
/* UTF-8 */
{ "UTF-8" , "utf-8" },
{ "UTF8" , "utf8" },
};
return true;
return false;
}
/**
* Init once for the path conversion code.
*
* @returns IPRT status code.
* @param pvUser1 Unused.
* @param pvUser2 Unused.
*/
{
/*
* Read the environment variable, no mercy on misconfigs here except that
* empty values are quietly ignored. (We use a temp buffer for stripping.)
*/
char *pszEnvValue = NULL;
char szEnvValue[sizeof(g_szFsCodeset)];
return rc;
if (RT_SUCCESS(rc))
if (pszEnvValue && *pszEnvValue)
{
}
else
{
const char *pszCodeset = rtStrGetLocaleCodeset();
if (cchCodeset >= sizeof(g_szFsCodeset))
/* This shouldn't happen, but we'll manage. */
g_szFsCodeset[0] = '\0';
else
{
}
}
return VINF_SUCCESS;
}
{
*ppszNativePath = NULL;
if (RT_SUCCESS(rc))
{
if (g_fPassthruUtf8 || !*pszPath)
else
(char **)ppszNativePath, 0, g_szFsCodeset,
2, g_enmUtf8ToFsIdx);
}
return rc;
}
{
if ( pszNativePath != pszPath
&& pszNativePath)
RTStrFree((char *)pszNativePath);
}
{
if (RT_SUCCESS(rc))
{
if (g_fPassthruUtf8 || !*pszNativePath)
{
if (RT_SUCCESS(rc))
{
char *pszPath;
if (pszPath)
else
}
}
else
(char **)ppszPath, 0, "UTF-8",
2, g_enmFsToUtf8Idx);
}
return rc;
}
{
if ( pszPath != pszNativePath
&& pszPath)
}
int rtPathFromNativeCopy(char *pszPath, size_t cbPath, const char *pszNativePath, const char *pszBasePath)
{
if (RT_SUCCESS(rc))
{
if (g_fPassthruUtf8 || !*pszNativePath)
else if (cbPath)
2, g_enmFsToUtf8Idx);
else
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
if (g_fPassthruUtf8 || !*pszNativePath)
else
ppszPath, 0, "UTF-8",
2, g_enmFsToUtf8Idx);
}
return rc;
}