1 | /* $Id: pathhost-darwin.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Path Conversions, Darwin.
|
---|
4 | *
|
---|
5 | * On darwin path names on the disk are decomposed using normalization
|
---|
6 | * form D (NFD). Since this behavior is unique for the Mac, we will precompose
|
---|
7 | * the path name strings we get from the XNU kernel.
|
---|
8 | */
|
---|
9 |
|
---|
10 | /*
|
---|
11 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
12 | *
|
---|
13 | * This file is part of VirtualBox base platform packages, as
|
---|
14 | * available from https://www.virtualbox.org.
|
---|
15 | *
|
---|
16 | * This program is free software; you can redistribute it and/or
|
---|
17 | * modify it under the terms of the GNU General Public License
|
---|
18 | * as published by the Free Software Foundation, in version 3 of the
|
---|
19 | * License.
|
---|
20 | *
|
---|
21 | * This program is distributed in the hope that it will be useful, but
|
---|
22 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
24 | * General Public License for more details.
|
---|
25 | *
|
---|
26 | * You should have received a copy of the GNU General Public License
|
---|
27 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
28 | *
|
---|
29 | * The contents of this file may alternatively be used under the terms
|
---|
30 | * of the Common Development and Distribution License Version 1.0
|
---|
31 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
32 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
33 | * CDDL are applicable instead of those of the GPL.
|
---|
34 | *
|
---|
35 | * You may elect to license modified versions of this file under the
|
---|
36 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
37 | *
|
---|
38 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
39 | */
|
---|
40 |
|
---|
41 |
|
---|
42 | /*********************************************************************************************************************************
|
---|
43 | * Header Files *
|
---|
44 | *********************************************************************************************************************************/
|
---|
45 | #define LOG_GROUP RTLOGGROUP_PATH
|
---|
46 | #include <iprt/assert.h>
|
---|
47 | #include <iprt/string.h>
|
---|
48 | #include "internal/iprt.h"
|
---|
49 |
|
---|
50 | #include "internal/path.h"
|
---|
51 |
|
---|
52 |
|
---|
53 | int rtPathToNative(const char **ppszNativePath, const char *pszPath, const char *pszBasePath)
|
---|
54 | {
|
---|
55 | /** @todo We should decompose the string here, but the file system will do
|
---|
56 | * that for us if we don't, so why bother. */
|
---|
57 | *ppszNativePath = (char *)pszPath;
|
---|
58 | NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
|
---|
59 | return VINF_SUCCESS;
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | void rtPathFreeNative(char const *pszNativePath, const char *pszPath)
|
---|
64 | {
|
---|
65 | Assert(pszNativePath == pszPath || !pszNativePath);
|
---|
66 | NOREF(pszNativePath);
|
---|
67 | NOREF(pszPath);
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | int rtPathFromNative(char const **ppszPath, const char *pszNativePath, const char *pszBasePath)
|
---|
72 | {
|
---|
73 | /** @todo We must compose the codepoints in the string here. We get file names
|
---|
74 | * in normalization form D so we'll end up with normalization form C
|
---|
75 | * whatever approach we take. */
|
---|
76 | int rc = RTStrValidateEncodingEx(pszNativePath, RTSTR_MAX, 0 /*fFlags*/);
|
---|
77 | if (RT_SUCCESS(rc))
|
---|
78 | *ppszPath = pszNativePath;
|
---|
79 | else
|
---|
80 | *ppszPath = NULL;
|
---|
81 | NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
|
---|
82 | return rc;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | void rtPathFreeIprt(const char *pszPath, const char *pszNativePath)
|
---|
87 | {
|
---|
88 | Assert(pszPath == pszNativePath || !pszPath);
|
---|
89 | NOREF(pszPath); NOREF(pszNativePath);
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | int rtPathFromNativeCopy(char *pszPath, size_t cbPath, const char *pszNativePath, const char *pszBasePath)
|
---|
94 | {
|
---|
95 | /** @todo We must compose the codepoints in the string here. We get file names
|
---|
96 | * in normalization form D so we'll end up with normalization form C
|
---|
97 | * whatever approach we take. */
|
---|
98 | int rc = RTStrValidateEncodingEx(pszNativePath, RTSTR_MAX, 0 /*fFlags*/);
|
---|
99 | if (RT_SUCCESS(rc))
|
---|
100 | rc = RTStrCopyEx(pszPath, cbPath, pszNativePath, RTSTR_MAX);
|
---|
101 | NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
|
---|
102 | return rc;
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | int rtPathFromNativeDup(char **ppszPath, const char *pszNativePath, const char *pszBasePath)
|
---|
107 | {
|
---|
108 | /** @todo We must compose the codepoints in the string here. We get file names
|
---|
109 | * in normalization form D so we'll end up with normalization form C
|
---|
110 | * whatever approach we take. */
|
---|
111 | int rc = RTStrValidateEncodingEx(pszNativePath, RTSTR_MAX, 0 /*fFlags*/);
|
---|
112 | if (RT_SUCCESS(rc))
|
---|
113 | rc = RTStrDupEx(ppszPath, pszNativePath);
|
---|
114 | NOREF(pszBasePath); /* We don't query the FS for codeset preferences. */
|
---|
115 | return rc;
|
---|
116 | }
|
---|
117 |
|
---|