3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync/* $Id$ */
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync/** @file
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * IPRT - Path Conversions, Darwin.
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync *
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * On darwin path names on the disk are decomposed using normalization
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * form D (NFD). Since this behavior is unique for the Mac, we will precompose
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * the path name strings we get from the XNU kernel.
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync */
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync/*
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * Copyright (C) 2006-2010 Oracle Corporation
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync *
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * available from http://www.virtualbox.org. This file is free software;
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * you can redistribute it and/or modify it under the terms of the GNU
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * General Public License (GPL) as published by the Free Software
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync *
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * The contents of this file may alternatively be used under the terms
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * of the Common Development and Distribution License Version 1.0
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * VirtualBox OSE distribution, in which case the provisions of the
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * CDDL are applicable instead of those of the GPL.
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync *
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * You may elect to license modified versions of this file under the
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * terms and conditions of either the GPL or the CDDL or both.
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync */
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync/*******************************************************************************
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync* Header Files *
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync*******************************************************************************/
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync#define LOG_GROUP RTLOGGROUP_PATH
ed0cf28a5770089e1c761249fd7fb90a6f3ce015vboxsync#include <iprt/assert.h>
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync#include <iprt/string.h>
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync#include "internal/iprt.h"
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync#include "internal/path.h"
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
95bbd60a323feec1eaf008a93690364eea86c298vboxsyncint rtPathToNative(const char **ppszNativePath, const char *pszPath, const char *pszBasePath)
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync{
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync /** @todo We should decompose the string here, but the file system will do
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * that for us if we don't, so why bother. */
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync *ppszNativePath = (char *)pszPath;
95bbd60a323feec1eaf008a93690364eea86c298vboxsync NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync return VINF_SUCCESS;
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync}
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
95bbd60a323feec1eaf008a93690364eea86c298vboxsyncvoid rtPathFreeNative(char const *pszNativePath, const char *pszPath)
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync{
95bbd60a323feec1eaf008a93690364eea86c298vboxsync Assert(pszNativePath == pszPath || !pszNativePath);
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync NOREF(pszNativePath);
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync NOREF(pszPath);
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync}
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
95bbd60a323feec1eaf008a93690364eea86c298vboxsyncint rtPathFromNative(char const **ppszPath, const char *pszNativePath, const char *pszBasePath)
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync{
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync /** @todo We must compose the codepoints in the string here. We get file names
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * in normalization form D so we'll end up with normalization form C
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync * whatever approach we take. */
95bbd60a323feec1eaf008a93690364eea86c298vboxsync int rc = RTStrValidateEncodingEx(pszNativePath, RTSTR_MAX, 0 /*fFlags*/);
95bbd60a323feec1eaf008a93690364eea86c298vboxsync if (RT_SUCCESS(rc))
95bbd60a323feec1eaf008a93690364eea86c298vboxsync *ppszPath = pszNativePath;
b8f36130d88425e8f9b4c58ae25562f5022573f2vboxsync else
b8f36130d88425e8f9b4c58ae25562f5022573f2vboxsync *ppszPath = NULL;
95bbd60a323feec1eaf008a93690364eea86c298vboxsync NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
95bbd60a323feec1eaf008a93690364eea86c298vboxsync return rc;
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync}
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
95bbd60a323feec1eaf008a93690364eea86c298vboxsyncvoid rtPathFreeIprt(const char *pszPath, const char *pszNativePath)
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync{
95bbd60a323feec1eaf008a93690364eea86c298vboxsync Assert(pszPath == pszNativePath || !pszPath);
95bbd60a323feec1eaf008a93690364eea86c298vboxsync NOREF(pszPath); NOREF(pszNativePath);
95bbd60a323feec1eaf008a93690364eea86c298vboxsync}
95bbd60a323feec1eaf008a93690364eea86c298vboxsync
95bbd60a323feec1eaf008a93690364eea86c298vboxsync
95bbd60a323feec1eaf008a93690364eea86c298vboxsyncint rtPathFromNativeCopy(char *pszPath, size_t cbPath, const char *pszNativePath, const char *pszBasePath)
95bbd60a323feec1eaf008a93690364eea86c298vboxsync{
95bbd60a323feec1eaf008a93690364eea86c298vboxsync /** @todo We must compose the codepoints in the string here. We get file names
95bbd60a323feec1eaf008a93690364eea86c298vboxsync * in normalization form D so we'll end up with normalization form C
95bbd60a323feec1eaf008a93690364eea86c298vboxsync * whatever approach we take. */
95bbd60a323feec1eaf008a93690364eea86c298vboxsync int rc = RTStrValidateEncodingEx(pszNativePath, RTSTR_MAX, 0 /*fFlags*/);
95bbd60a323feec1eaf008a93690364eea86c298vboxsync if (RT_SUCCESS(rc))
95bbd60a323feec1eaf008a93690364eea86c298vboxsync rc = RTStrCopyEx(pszPath, cbPath, pszNativePath, RTSTR_MAX);
95bbd60a323feec1eaf008a93690364eea86c298vboxsync NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
95bbd60a323feec1eaf008a93690364eea86c298vboxsync return rc;
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync}
3490d4bf2a8a1834a93809283876d4ec7077ec80vboxsync
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsyncint rtPathFromNativeDup(char **ppszPath, const char *pszNativePath, const char *pszBasePath)
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync{
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync /** @todo We must compose the codepoints in the string here. We get file names
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync * in normalization form D so we'll end up with normalization form C
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync * whatever approach we take. */
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync int rc = RTStrValidateEncodingEx(pszNativePath, RTSTR_MAX, 0 /*fFlags*/);
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync if (RT_SUCCESS(rc))
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync rc = RTStrDupEx(ppszPath, pszNativePath);
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync return rc;
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync}
c9579522f347fc3fda6b3f4add0b355981cd7758vboxsync