summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2022-09-06 14:13:23 +0000
committervboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2022-09-06 14:13:23 +0000
commit3e441fc9bc78cb7bf056f648f17cfe07f8aa5579 (patch)
tree7c2092d0be88ff1797805399ef70a45c431bc2de
parentd575e6392ea9caccb619b3b4ab18f993451a1ba4 (diff)
downloadVirtualBox-svn-3e441fc9bc78cb7bf056f648f17cfe07f8aa5579.tar.gz
IPRT/path: Added fFlags parameter to RTPathAppendEx and RTPathJoinEx to make it possible to select the path style. bugref:10286
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@96609 cfe28804-0f27-0410-a406-dd0f0b0b656f
-rw-r--r--src/VBox/HostServices/SharedFolders/vbsfpath.cpp2
-rw-r--r--src/VBox/Runtime/common/path/RTPathAppend.cpp2
-rw-r--r--src/VBox/Runtime/common/path/RTPathAppendEx.cpp70
-rw-r--r--src/VBox/Runtime/common/path/RTPathAppendEx.cpp.h166
-rw-r--r--src/VBox/Runtime/common/path/RTPathJoinEx.cpp5
-rw-r--r--src/VBox/Runtime/r3/posix/process-creation-posix.cpp3
-rw-r--r--src/VBox/Runtime/r3/win/process-win.cpp2
-rw-r--r--src/VBox/Runtime/testcase/tstRTPath.cpp151
-rw-r--r--src/VBox/Runtime/tools/RTDbgSymCache.cpp4
-rw-r--r--src/VBox/VMM/VMMR3/PDMLdr.cpp2
10 files changed, 272 insertions, 135 deletions
diff --git a/src/VBox/HostServices/SharedFolders/vbsfpath.cpp b/src/VBox/HostServices/SharedFolders/vbsfpath.cpp
index 9eee75d3dc3..0fcdf5b76ac 100644
--- a/src/VBox/HostServices/SharedFolders/vbsfpath.cpp
+++ b/src/VBox/HostServices/SharedFolders/vbsfpath.cpp
@@ -112,7 +112,7 @@ static int vbsfCorrectCasing(SHFLCLIENTDATA *pClient, char *pszFullPath, char *p
/** @todo Use RTDirOpen here and drop the whole uncessary path copying? */
int rc = RTPathJoinEx(pDirEntry->szName, cbDirEntry - RT_OFFSETOF(RTDIRENTRYEX, szName),
pszFullPath, cchParentDir,
- RT_STR_TUPLE("*"));
+ RT_STR_TUPLE("*"), RTPATH_STR_F_STYLE_HOST);
AssertRC(rc);
if (RT_SUCCESS(rc))
{
diff --git a/src/VBox/Runtime/common/path/RTPathAppend.cpp b/src/VBox/Runtime/common/path/RTPathAppend.cpp
index 2b4e08aa994..a1cf4b1c7d2 100644
--- a/src/VBox/Runtime/common/path/RTPathAppend.cpp
+++ b/src/VBox/Runtime/common/path/RTPathAppend.cpp
@@ -46,6 +46,6 @@
RTDECL(int) RTPathAppend(char *pszPath, size_t cbPathDst, const char *pszAppend)
{
- return RTPathAppendEx(pszPath, cbPathDst, pszAppend, RTSTR_MAX);
+ return RTPathAppendEx(pszPath, cbPathDst, pszAppend, RTSTR_MAX, RTPATH_STR_F_STYLE_HOST);
}
diff --git a/src/VBox/Runtime/common/path/RTPathAppendEx.cpp b/src/VBox/Runtime/common/path/RTPathAppendEx.cpp
index d2e66be9598..078d9f02cbd 100644
--- a/src/VBox/Runtime/common/path/RTPathAppendEx.cpp
+++ b/src/VBox/Runtime/common/path/RTPathAppendEx.cpp
@@ -46,6 +46,9 @@
#include <iprt/errcore.h>
#include <iprt/string.h>
+#define RTPATH_TEMPLATE_CPP_H "RTPathAppendEx.cpp.h"
+#include "rtpath-expand-template.cpp.h"
+
/**
* Figures the length of the root part of the path.
@@ -114,10 +117,11 @@ static size_t rtPathRootSpecLen2(const char *pszPath)
}
-RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppend, size_t cchAppendMax)
+RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppend, size_t cchAppendMax, uint32_t fFlags)
{
char *pszPathEnd = RTStrEnd(pszPath, cbPathDst);
AssertReturn(pszPathEnd, VERR_INVALID_PARAMETER);
+ Assert(RTPATH_STR_F_IS_VALID(fFlags, 0));
/*
* Special cases.
@@ -137,60 +141,24 @@ RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppen
}
/*
- * Balance slashes and check for buffer overflow.
+ * Go to path style specific code now.
*/
- if (!RTPATH_IS_SLASH(pszPathEnd[-1]))
+ switch (fFlags & RTPATH_STR_F_STYLE_MASK)
{
- if (!RTPATH_IS_SLASH(pszAppend[0]))
- {
-#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
- if ( (size_t)(pszPathEnd - pszPath) == 2
- && pszPath[1] == ':'
- && RT_C_IS_ALPHA(pszPath[0]))
- {
- if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst)
- return VERR_BUFFER_OVERFLOW;
- }
- else
+#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
+ case RTPATH_STR_F_STYLE_HOST:
#endif
- {
- if ((size_t)(pszPathEnd - pszPath) + 1 + cchAppend >= cbPathDst)
- return VERR_BUFFER_OVERFLOW;
- *pszPathEnd++ = RTPATH_SLASH;
- }
- }
- else
- {
- /* One slash is sufficient at this point. */
- while (cchAppend > 1 && RTPATH_IS_SLASH(pszAppend[1]))
- pszAppend++, cchAppend--;
+ case RTPATH_STR_F_STYLE_DOS:
+ return rtPathAppendExStyleDos(pszPath, cbPathDst, pszPathEnd, pszAppend, cchAppend);
- if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst)
- return VERR_BUFFER_OVERFLOW;
- }
- }
- else
- {
- /* No slashes needed in the appended bit. */
- while (cchAppend && RTPATH_IS_SLASH(*pszAppend))
- pszAppend++, cchAppend--;
-
- /* In the leading path we can skip unnecessary trailing slashes, but
- be sure to leave one. */
- size_t const cchRoot = rtPathRootSpecLen2(pszPath);
- while ( (size_t)(pszPathEnd - pszPath) > RT_MAX(1, cchRoot)
- && RTPATH_IS_SLASH(pszPathEnd[-2]))
- pszPathEnd--;
-
- if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst)
- return VERR_BUFFER_OVERFLOW;
- }
+#if RTPATH_STYLE != RTPATH_STR_F_STYLE_DOS
+ case RTPATH_STR_F_STYLE_HOST:
+#endif
+ case RTPATH_STR_F_STYLE_UNIX:
+ return rtPathAppendExStyleUnix(pszPath, cbPathDst, pszPathEnd, pszAppend, cchAppend);
- /*
- * What remains now is the just the copying.
- */
- memcpy(pszPathEnd, pszAppend, cchAppend);
- pszPathEnd[cchAppend] = '\0';
- return VINF_SUCCESS;
+ default:
+ AssertFailedReturn(VERR_INVALID_FLAGS); /* impossible */
+ }
}
diff --git a/src/VBox/Runtime/common/path/RTPathAppendEx.cpp.h b/src/VBox/Runtime/common/path/RTPathAppendEx.cpp.h
new file mode 100644
index 00000000000..592ad3d2cc0
--- /dev/null
+++ b/src/VBox/Runtime/common/path/RTPathAppendEx.cpp.h
@@ -0,0 +1,166 @@
+/* $Id$ */
+/** @file
+ * IPRT - rtPathAppendEx - Code Template.
+ */
+
+/*
+ * Copyright (C) 2009-2022 Oracle and/or its affiliates.
+ *
+ * This file is part of VirtualBox base platform packages, as
+ * available from https://www.virtualbox.org.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, in version 3 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses>.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
+ * in the VirtualBox 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.
+ *
+ * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
+ */
+
+
+/**
+ * Figures the length of the root part of the path.
+ *
+ * @returns length of the root specifier.
+ * @retval 0 if none.
+ *
+ * @param pszPath The path to investigate.
+ *
+ * @remarks Unnecessary root slashes will not be counted. The caller will have
+ * to deal with it where it matters. (Unlike rtPathRootSpecLen which
+ * counts them.)
+ */
+DECLINLINE(size_t) RTPATH_STYLE_FN(rtPathRootSpecLen2)(const char *pszPath)
+{
+ /* fend of wildlife. */
+ if (!pszPath)
+ return 0;
+
+ /* Root slash? */
+ if (RTPATH_IS_SLASH(pszPath[0]))
+ {
+#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
+ /* UNC? */
+ if ( RTPATH_IS_SLASH(pszPath[1])
+ && pszPath[2] != '\0'
+ && !RTPATH_IS_SLASH(pszPath[2]))
+ {
+ /* Find the end of the server name. */
+ const char *pszEnd = pszPath + 2;
+ pszEnd += 2;
+ while ( *pszEnd != '\0'
+ && !RTPATH_IS_SLASH(*pszEnd))
+ pszEnd++;
+ if (RTPATH_IS_SLASH(*pszEnd))
+ {
+ pszEnd++;
+ while (RTPATH_IS_SLASH(*pszEnd))
+ pszEnd++;
+
+ /* Find the end of the share name */
+ while ( *pszEnd != '\0'
+ && !RTPATH_IS_SLASH(*pszEnd))
+ pszEnd++;
+ if (RTPATH_IS_SLASH(*pszEnd))
+ pszEnd++;
+ return pszPath - pszEnd;
+ }
+ }
+#endif
+ return 1;
+ }
+
+#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
+ /* Drive specifier? */
+ if ( pszPath[0] != '\0'
+ && pszPath[1] == ':'
+ && RT_C_IS_ALPHA(pszPath[0]))
+ {
+ if (RTPATH_IS_SLASH(pszPath[2]))
+ return 3;
+ return 2;
+ }
+#endif
+ return 0;
+}
+
+
+/** Internal worker for RTPathAppendEx. */
+DECLINLINE(int) RTPATH_STYLE_FN(rtPathAppendEx)(char *pszPath, size_t cbPathDst, char *pszPathEnd,
+ const char *pszAppend, size_t cchAppend)
+{
+ /*
+ * Balance slashes and check for buffer overflow.
+ */
+ if (!RTPATH_IS_SLASH(pszPathEnd[-1]))
+ {
+ if (!RTPATH_IS_SLASH(pszAppend[0]))
+ {
+#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
+ if ( (size_t)(pszPathEnd - pszPath) == 2
+ && pszPath[1] == ':'
+ && RT_C_IS_ALPHA(pszPath[0]))
+ {
+ if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst)
+ return VERR_BUFFER_OVERFLOW;
+ }
+ else
+#endif
+ {
+ if ((size_t)(pszPathEnd - pszPath) + 1 + cchAppend >= cbPathDst)
+ return VERR_BUFFER_OVERFLOW;
+ *pszPathEnd++ = RTPATH_SLASH;
+ }
+ }
+ else
+ {
+ /* One slash is sufficient at this point. */
+ while (cchAppend > 1 && RTPATH_IS_SLASH(pszAppend[1]))
+ pszAppend++, cchAppend--;
+
+ if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst)
+ return VERR_BUFFER_OVERFLOW;
+ }
+ }
+ else
+ {
+ /* No slashes needed in the appended bit. */
+ while (cchAppend && RTPATH_IS_SLASH(*pszAppend))
+ pszAppend++, cchAppend--;
+
+ /* In the leading path we can skip unnecessary trailing slashes, but
+ be sure to leave one. */
+ size_t const cchRoot = RTPATH_STYLE_FN(rtPathRootSpecLen2)(pszPath);
+ while ( (size_t)(pszPathEnd - pszPath) > RT_MAX(1, cchRoot)
+ && RTPATH_IS_SLASH(pszPathEnd[-2]))
+ pszPathEnd--;
+
+ if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst)
+ return VERR_BUFFER_OVERFLOW;
+ }
+
+ /*
+ * What remains now is the just the copying.
+ */
+ memcpy(pszPathEnd, pszAppend, cchAppend);
+ pszPathEnd[cchAppend] = '\0';
+ return VINF_SUCCESS;
+}
+
diff --git a/src/VBox/Runtime/common/path/RTPathJoinEx.cpp b/src/VBox/Runtime/common/path/RTPathJoinEx.cpp
index 46ff27ab21f..f216398f5ad 100644
--- a/src/VBox/Runtime/common/path/RTPathJoinEx.cpp
+++ b/src/VBox/Runtime/common/path/RTPathJoinEx.cpp
@@ -49,11 +49,12 @@
RTDECL(int) RTPathJoinEx(char *pszPathDst, size_t cbPathDst,
const char *pszPathSrc, size_t cchPathSrcMax,
- const char *pszAppend, size_t cchAppendMax)
+ const char *pszAppend, size_t cchAppendMax, uint32_t fFlags)
{
AssertPtr(pszPathDst);
AssertPtr(pszPathSrc);
AssertPtr(pszAppend);
+ Assert(RTPATH_STR_F_IS_VALID(fFlags, 0));
/*
* The easy way: Copy the path into the buffer and call RTPathAppend.
@@ -64,6 +65,6 @@ RTDECL(int) RTPathJoinEx(char *pszPathDst, size_t cbPathDst,
memcpy(pszPathDst, pszPathSrc, cchPathSrc);
pszPathDst[cchPathSrc] = '\0';
- return RTPathAppendEx(pszPathDst, cbPathDst, pszAppend, cchAppendMax);
+ return RTPathAppendEx(pszPathDst, cbPathDst, pszAppend, cchAppendMax, fFlags);
}
diff --git a/src/VBox/Runtime/r3/posix/process-creation-posix.cpp b/src/VBox/Runtime/r3/posix/process-creation-posix.cpp
index 7af69c92611..d64f1d53c69 100644
--- a/src/VBox/Runtime/r3/posix/process-creation-posix.cpp
+++ b/src/VBox/Runtime/r3/posix/process-creation-posix.cpp
@@ -1643,7 +1643,8 @@ static DECLCALLBACK(int) rtPathFindExec(char const *pchPath, size_t cchPath, voi
{
const char *pszExec = (const char *)pvUser1;
PRTPATHINTSEARCH pResult = (PRTPATHINTSEARCH)pvUser2;
- int rc = RTPathJoinEx(pResult->szFound, sizeof(pResult->szFound), pchPath, cchPath, pszExec, RTSTR_MAX);
+ int rc = RTPathJoinEx(pResult->szFound, sizeof(pResult->szFound), pchPath, cchPath, pszExec, RTSTR_MAX,
+ RTPATH_STR_F_STYLE_HOST);
if (RT_SUCCESS(rc))
{
const char *pszNativeExec = NULL;
diff --git a/src/VBox/Runtime/r3/win/process-win.cpp b/src/VBox/Runtime/r3/win/process-win.cpp
index 2577b21441f..2849de1649c 100644
--- a/src/VBox/Runtime/r3/win/process-win.cpp
+++ b/src/VBox/Runtime/r3/win/process-win.cpp
@@ -2121,7 +2121,7 @@ static DECLCALLBACK(int) rtPathFindExec(char const *pchPath, size_t cchPath, voi
{
const char *pszExec = (const char *)pvUser1;
char *pszRealExec = (char *)pvUser2;
- int rc = RTPathJoinEx(pszRealExec, RTPATH_MAX, pchPath, cchPath, pszExec, RTSTR_MAX);
+ int rc = RTPathJoinEx(pszRealExec, RTPATH_MAX, pchPath, cchPath, pszExec, RTSTR_MAX, RTPATH_STR_F_STYLE_HOST);
if (RT_FAILURE(rc))
return rc;
if (RTFileExists(pszRealExec))
diff --git a/src/VBox/Runtime/testcase/tstRTPath.cpp b/src/VBox/Runtime/testcase/tstRTPath.cpp
index 66e5184ec68..91ca9787ee2 100644
--- a/src/VBox/Runtime/testcase/tstRTPath.cpp
+++ b/src/VBox/Runtime/testcase/tstRTPath.cpp
@@ -835,77 +835,76 @@ int main()
* RTPathAppend.
*/
RTTestSub(hTest, "RTPathAppend");
- static const char *s_apszAppendTests[] =
+ static struct { uint32_t fFlags; const char *pszInput, *pszAppend, *pszExpect; } s_aAppendTests[] =
{
- /* base append result */
- "/", "", "/",
- "", "/", "/",
- "/", "/", "/",
- "/x", "", "/x",
- "/x", "/", "/x/",
- "/", "x", "/x",
- "dir", "file", "dir" RTPATH_SLASH_STR "file",
- "dir", "/file", "dir/file",
- "dir", "//file", "dir/file",
- "dir", "///file", "dir/file",
- "dir/", "/file", "dir/file",
- "dir/", "//file", "dir/file",
- "dir/", "///file", "dir/file",
- "dir//", "file", "dir/file",
- "dir//", "/file", "dir/file",
- "dir//", "//file", "dir/file",
- "dir///", "///file", "dir/file",
- "/bin/testcase", "foo.r0", "/bin/testcase" RTPATH_SLASH_STR "foo.r0",
-#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
- "/", "\\", "/",
- "\\", "/", "\\",
- "\\\\srv\\shr", "dir//", "\\\\srv\\shr" RTPATH_SLASH_STR "dir//",
- "\\\\srv\\shr", "dir//file", "\\\\srv\\shr" RTPATH_SLASH_STR "dir//file",
- "\\\\srv\\shr", "//dir//", "\\\\srv\\shr/dir//",
- "\\\\srv\\shr", "/\\dir//", "\\\\srv\\shr\\dir//",
- "\\\\", "not-srv/not-shr/file", "\\not-srv/not-shr/file",
- "C:", "autoexec.bat", "C:autoexec.bat",
- "C:", "/autoexec.bat", "C:/autoexec.bat",
- "C:", "\\autoexec.bat", "C:\\autoexec.bat",
- "C:\\", "/autoexec.bat", "C:\\autoexec.bat",
- "C:\\\\", "autoexec.bat", "C:\\autoexec.bat",
- "E:\\bin\\testcase", "foo.r0", "E:\\bin\\testcase" RTPATH_SLASH_STR "foo.r0",
-#endif
+ /* fFlags, input append expected result */
+ { RTPATH_STR_F_STYLE_HOST, "/", "", "/" },
+ { RTPATH_STR_F_STYLE_HOST, "", "/", "/" },
+ { RTPATH_STR_F_STYLE_HOST, "/", "/", "/" },
+ { RTPATH_STR_F_STYLE_HOST, "/x", "", "/x" },
+ { RTPATH_STR_F_STYLE_HOST, "/x", "/", "/x/" },
+ { RTPATH_STR_F_STYLE_HOST, "/", "x", "/x" },
+ { RTPATH_STR_F_STYLE_HOST, "dir", "file", "dir" RTPATH_SLASH_STR "file" },
+ { RTPATH_STR_F_STYLE_HOST, "dir", "/file", "dir/file" },
+ { RTPATH_STR_F_STYLE_HOST, "dir", "//file", "dir/file" },
+ { RTPATH_STR_F_STYLE_HOST, "dir", "///file", "dir/file" },
+ { RTPATH_STR_F_STYLE_HOST, "dir/", "/file", "dir/file" },
+ { RTPATH_STR_F_STYLE_HOST, "dir/", "//file", "dir/file" },
+ { RTPATH_STR_F_STYLE_HOST, "dir/", "///file", "dir/file" },
+ { RTPATH_STR_F_STYLE_HOST, "dir//", "file", "dir/file" },
+ { RTPATH_STR_F_STYLE_HOST, "dir//", "/file", "dir/file" },
+ { RTPATH_STR_F_STYLE_HOST, "dir//", "//file", "dir/file" },
+ { RTPATH_STR_F_STYLE_HOST, "dir///", "///file", "dir/file" },
+ { RTPATH_STR_F_STYLE_HOST, "/bin/testcase", "foo.r0", "/bin/testcase" RTPATH_SLASH_STR "foo.r0" },
+ { RTPATH_STR_F_STYLE_DOS, "/", "\\", "/" },
+ { RTPATH_STR_F_STYLE_DOS, "\\", "/", "\\" },
+ { RTPATH_STR_F_STYLE_DOS, "\\\\srv\\shr", "dir//", "\\\\srv\\shr\\dir//" },
+ { RTPATH_STR_F_STYLE_DOS, "\\\\srv\\shr", "dir//file", "\\\\srv\\shr\\dir//file" },
+ { RTPATH_STR_F_STYLE_DOS, "\\\\srv\\shr", "//dir//", "\\\\srv\\shr/dir//" },
+ { RTPATH_STR_F_STYLE_DOS, "\\\\srv\\shr", "/\\dir//", "\\\\srv\\shr\\dir//" },
+ { RTPATH_STR_F_STYLE_DOS, "\\\\", "not-srv/not-shr/file", "\\not-srv/not-shr/file" },
+ { RTPATH_STR_F_STYLE_DOS, "C:", "autoexec.bat", "C:autoexec.bat" },
+ { RTPATH_STR_F_STYLE_DOS, "C:", "/autoexec.bat", "C:/autoexec.bat" },
+ { RTPATH_STR_F_STYLE_DOS, "C:", "\\autoexec.bat", "C:\\autoexec.bat" },
+ { RTPATH_STR_F_STYLE_DOS, "C:\\", "/autoexec.bat", "C:\\autoexec.bat" },
+ { RTPATH_STR_F_STYLE_DOS, "C:\\\\", "autoexec.bat", "C:\\autoexec.bat" },
+ { RTPATH_STR_F_STYLE_DOS, "E:\\bin\\testcase", "foo.r0", "E:\\bin\\testcase\\foo.r0" },
+ { RTPATH_STR_F_STYLE_UNIX, "dir\\", "\\file", "dir\\/\\file" },
};
- for (unsigned i = 0; i < RT_ELEMENTS(s_apszAppendTests); i += 3)
+ for (unsigned i = 0; i < RT_ELEMENTS(s_aAppendTests); i++)
{
- const char *pszInput = s_apszAppendTests[i];
- const char *pszAppend = s_apszAppendTests[i + 1];
- const char *pszExpect = s_apszAppendTests[i + 2];
+ const char * const pszInput = s_aAppendTests[i].pszInput;
+ const char * const pszAppend = s_aAppendTests[i].pszAppend;
+ const char * const pszExpect = s_aAppendTests[i].pszExpect;
+ uint32_t const fFlags = s_aAppendTests[i].fFlags;
+
strcpy(szPath, pszInput);
- RTTESTI_CHECK_RC(rc = RTPathAppend(szPath, sizeof(szPath), pszAppend), VINF_SUCCESS);
+ RTTESTI_CHECK_RC(rc = RTPathAppendEx(szPath, sizeof(szPath), pszAppend, RTSTR_MAX, fFlags), VINF_SUCCESS);
if (RT_FAILURE(rc))
continue;
if (strcmp(szPath, pszExpect))
- {
RTTestIFailed("Unexpected result\n"
- " input: '%s'\n"
+ " input: '%s', fFlags=%#x\n"
" append: '%s'\n"
" output: '%s'\n"
"expected: '%s'",
- pszInput, pszAppend, szPath, pszExpect);
- }
+ pszInput, fFlags, pszAppend, szPath, pszExpect);
else
{
size_t const cchResult = strlen(szPath);
strcpy(szPath, pszInput);
- RTTESTI_CHECK_RC(rc = RTPathAppend(szPath, cchResult + 2, pszAppend), VINF_SUCCESS);
+ RTTESTI_CHECK_RC(rc = RTPathAppendEx(szPath, cchResult + 2, pszAppend, RTSTR_MAX, fFlags), VINF_SUCCESS);
RTTESTI_CHECK(RT_FAILURE(rc) || !strcmp(szPath, pszExpect));
strcpy(szPath, pszInput);
- RTTESTI_CHECK_RC(rc = RTPathAppend(szPath, cchResult + 1, pszAppend), VINF_SUCCESS);
+ RTTESTI_CHECK_RC(rc = RTPathAppendEx(szPath, cchResult + 1, pszAppend, RTSTR_MAX, fFlags), VINF_SUCCESS);
RTTESTI_CHECK(RT_FAILURE(rc) || !strcmp(szPath, pszExpect));
if (strlen(pszInput) < cchResult)
{
strcpy(szPath, pszInput);
- RTTESTI_CHECK_RC(RTPathAppend(szPath, cchResult, pszAppend), VERR_BUFFER_OVERFLOW);
+ RTTESTI_CHECK_RC(RTPathAppendEx(szPath, cchResult, pszAppend, RTSTR_MAX, fFlags), VERR_BUFFER_OVERFLOW);
}
}
}
@@ -914,39 +913,38 @@ int main()
* RTPathJoin - reuse the append tests.
*/
RTTestSub(hTest, "RTPathJoin");
- for (unsigned i = 0; i < RT_ELEMENTS(s_apszAppendTests); i += 3)
+ for (unsigned i = 0; i < RT_ELEMENTS(s_aAppendTests); i++)
{
- const char *pszInput = s_apszAppendTests[i];
- const char *pszAppend = s_apszAppendTests[i + 1];
- const char *pszExpect = s_apszAppendTests[i + 2];
+ const char * const pszInput = s_aAppendTests[i].pszInput;
+ const char * const pszAppend = s_aAppendTests[i].pszAppend;
+ const char * const pszExpect = s_aAppendTests[i].pszExpect;
+ uint32_t const fFlags = s_aAppendTests[i].fFlags;
memset(szPath, 'a', sizeof(szPath)); szPath[sizeof(szPath) - 1] = '\0';
- RTTESTI_CHECK_RC(rc = RTPathJoin(szPath, sizeof(szPath), pszInput, pszAppend), VINF_SUCCESS);
+ RTTESTI_CHECK_RC(rc = RTPathJoinEx(szPath, sizeof(szPath), pszInput, RTSTR_MAX, pszAppend, RTSTR_MAX, fFlags), VINF_SUCCESS);
if (RT_FAILURE(rc))
continue;
if (strcmp(szPath, pszExpect))
- {
RTTestIFailed("Unexpected result\n"
- " input: '%s'\n"
+ " input: '%s', fFlags=%#x\n"
" append: '%s'\n"
" output: '%s'\n"
"expected: '%s'",
- pszInput, pszAppend, szPath, pszExpect);
- }
+ pszInput, fFlags, pszAppend, szPath, pszExpect);
else
{
size_t const cchResult = strlen(szPath);
memset(szPath, 'a', sizeof(szPath)); szPath[sizeof(szPath) - 1] = '\0';
- RTTESTI_CHECK_RC(rc = RTPathJoin(szPath, cchResult + 2, pszInput, pszAppend), VINF_SUCCESS);
+ RTTESTI_CHECK_RC(rc = RTPathJoinEx(szPath, cchResult + 2, pszInput, RTSTR_MAX, pszAppend, RTSTR_MAX, fFlags), VINF_SUCCESS);
RTTESTI_CHECK(RT_FAILURE(rc) || !strcmp(szPath, pszExpect));
memset(szPath, 'a', sizeof(szPath)); szPath[sizeof(szPath) - 1] = '\0';
- RTTESTI_CHECK_RC(rc = RTPathJoin(szPath, cchResult + 1, pszInput, pszAppend), VINF_SUCCESS);
+ RTTESTI_CHECK_RC(rc = RTPathJoinEx(szPath, cchResult + 1, pszInput, RTSTR_MAX, pszAppend, RTSTR_MAX, fFlags), VINF_SUCCESS);
RTTESTI_CHECK(RT_FAILURE(rc) || !strcmp(szPath, pszExpect));
- RTTESTI_CHECK_RC(rc = RTPathJoin(szPath, cchResult, pszInput, pszAppend), VERR_BUFFER_OVERFLOW);
+ RTTESTI_CHECK_RC(rc = RTPathJoinEx(szPath, cchResult, pszInput, RTSTR_MAX, pszAppend, RTSTR_MAX, fFlags), VERR_BUFFER_OVERFLOW);
}
}
@@ -954,26 +952,29 @@ int main()
* RTPathJoinA - reuse the append tests.
*/
RTTestSub(hTest, "RTPathJoinA");
- for (unsigned i = 0; i < RT_ELEMENTS(s_apszAppendTests); i += 3)
+ for (unsigned i = 0; i < RT_ELEMENTS(s_aAppendTests); i++)
{
- const char *pszInput = s_apszAppendTests[i];
- const char *pszAppend = s_apszAppendTests[i + 1];
- const char *pszExpect = s_apszAppendTests[i + 2];
+ const char * const pszInput = s_aAppendTests[i].pszInput;
+ const char * const pszAppend = s_aAppendTests[i].pszAppend;
+ const char * const pszExpect = s_aAppendTests[i].pszExpect;
+ uint32_t const fFlags = s_aAppendTests[i].fFlags;
+ if ( (fFlags & RTPATH_STR_F_STYLE_MASK) == RTPATH_STR_F_STYLE_HOST
+ || (fFlags & RTPATH_STR_F_STYLE_MASK) == RTPATH_STYLE)
- char *pszPathDst;
- RTTESTI_CHECK(pszPathDst = RTPathJoinA(pszInput, pszAppend));
- if (!pszPathDst)
- continue;
- if (strcmp(pszPathDst, pszExpect))
{
- RTTestIFailed("Unexpected result\n"
- " input: '%s'\n"
- " append: '%s'\n"
- " output: '%s'\n"
- "expected: '%s'",
- pszInput, pszAppend, pszPathDst, pszExpect);
+ char *pszPathDst;
+ RTTESTI_CHECK(pszPathDst = RTPathJoinA(pszInput, pszAppend));
+ if (!pszPathDst)
+ continue;
+ if (strcmp(pszPathDst, pszExpect))
+ RTTestIFailed("Unexpected result\n"
+ " input: '%s'\n"
+ " append: '%s'\n"
+ " output: '%s'\n"
+ "expected: '%s'",
+ pszInput, pszAppend, pszPathDst, pszExpect);
+ RTStrFree(pszPathDst);
}
- RTStrFree(pszPathDst);
}
/*
diff --git a/src/VBox/Runtime/tools/RTDbgSymCache.cpp b/src/VBox/Runtime/tools/RTDbgSymCache.cpp
index 264d5a5d207..d2a294ecea7 100644
--- a/src/VBox/Runtime/tools/RTDbgSymCache.cpp
+++ b/src/VBox/Runtime/tools/RTDbgSymCache.cpp
@@ -815,7 +815,7 @@ static int rtDbgSymCacheConstructBundlePath(char *pszPath, size_t cchPath, size_
* Check the immediate directory first, in case it's layed out like
* IOPCIFamily.kext.
*/
- int rc = RTPathAppendEx(pszPath, RTPATH_MAX, &pszPath[cchPath], cchName);
+ int rc = RTPathAppendEx(pszPath, RTPATH_MAX, &pszPath[cchPath], cchName, RTPATH_STR_F_STYLE_HOST);
if (RT_FAILURE(rc) || !RTFileExists(pszPath))
{
/*
@@ -824,7 +824,7 @@ static int rtDbgSymCacheConstructBundlePath(char *pszPath, size_t cchPath, size_
pszPath[cchPath + cchOrgName] = '\0';
rc = RTPathAppend(pszPath, RTPATH_MAX, pszSubDir);
if (RT_SUCCESS(rc))
- rc = RTPathAppendEx(pszPath, RTPATH_MAX, &pszPath[cchPath], cchName);
+ rc = RTPathAppendEx(pszPath, RTPATH_MAX, &pszPath[cchPath], cchName, RTPATH_STR_F_STYLE_HOST);
if (RT_FAILURE(rc))
{
pszPath[cchPath + cchOrgName] = '\0';
diff --git a/src/VBox/VMM/VMMR3/PDMLdr.cpp b/src/VBox/VMM/VMMR3/PDMLdr.cpp
index 0bf9e3c64e6..9d294d19701 100644
--- a/src/VBox/VMM/VMMR3/PDMLdr.cpp
+++ b/src/VBox/VMM/VMMR3/PDMLdr.cpp
@@ -1226,7 +1226,7 @@ static char *pdmR3File(const char *pszFile, const char *pszDefaultExt, const cha
pszNext = pszEnd + 1;
if (pszEnd != psz)
{
- rc = RTPathJoinEx(szPath, sizeof(szPath), psz, pszEnd - psz, pszFile, cchFile);
+ rc = RTPathJoinEx(szPath, sizeof(szPath), psz, pszEnd - psz, pszFile, cchFile, RTPATH_STR_F_STYLE_HOST);
if (RT_SUCCESS(rc))
{
if (RTFileExists(szPath))