VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/path/RTPathFindCommon.cpp

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* $Id: RTPathFindCommon.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - RTPathFindCommon implementations.
4 */
5
6/*
7 * Copyright (C) 2020-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "internal/iprt.h"
42#include <iprt/path.h>
43
44#include <iprt/alloca.h>
45#include <iprt/assert.h>
46#include <iprt/errcore.h>
47#include <iprt/mem.h>
48#include <iprt/string.h>
49#include <iprt/uni.h>
50
51
52#define RTPATH_TEMPLATE_CPP_H "RTPathFindCommon.cpp.h"
53#include "rtpath-expand-template.cpp.h"
54
55
56RTDECL(size_t) RTPathFindCommonEx(size_t cPaths, const char * const *papszPaths, uint32_t fFlags)
57{
58 /*
59 * Validate input.
60 */
61 AssertReturn(RTPATH_STR_F_IS_VALID(fFlags, RTPATHFINDCOMMON_F_IGNORE_DOTDOT), 0);
62 AssertReturn(cPaths > 0, 0);
63 AssertPtrReturn(papszPaths, 0);
64 size_t i = cPaths;
65 while (i-- > 0)
66 AssertPtrReturn(papszPaths[i], 0);
67
68 /*
69 * Duplicate papszPaths so we can have individual positions in each path.
70 * Use the stack if we haven't got too many paths.
71 */
72 void *pvFree;
73 const char **papszCopy;
74 size_t cbNeeded = cPaths * sizeof(papszCopy[0]);
75 if (cbNeeded <= _2K)
76 {
77 pvFree = NULL;
78 papszCopy = (const char **)alloca(cbNeeded);
79 }
80 else
81 {
82 pvFree = RTMemTmpAlloc(cbNeeded);
83 papszCopy = (const char **)pvFree;
84 }
85 AssertReturn(papszCopy, 0);
86 memcpy(papszCopy, papszPaths, cbNeeded);
87
88 /*
89 * Invoke the worker for the selected path style.
90 */
91 size_t cchRet;
92 switch (fFlags & RTPATH_STR_F_STYLE_MASK)
93 {
94#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
95 case RTPATH_STR_F_STYLE_HOST:
96#endif
97 case RTPATH_STR_F_STYLE_DOS:
98 cchRet= rtPathFindCommonStyleDos(cPaths, papszCopy, fFlags);
99 break;
100
101#if RTPATH_STYLE != RTPATH_STR_F_STYLE_DOS
102 case RTPATH_STR_F_STYLE_HOST:
103#endif
104 case RTPATH_STR_F_STYLE_UNIX:
105 cchRet = rtPathFindCommonStyleUnix(cPaths, papszCopy, fFlags);
106 break;
107
108 default:
109 AssertFailedStmt(cchRet = 0); /* impossible */
110 }
111
112 /*
113 * Clean up and return.
114 */
115 if (pvFree)
116 RTMemTmpFree(pvFree);
117 return cchRet;
118}
119RT_EXPORT_SYMBOL(RTPathFindCommonEx);
120
121
122RTDECL(size_t) RTPathFindCommon(size_t cPaths, const char * const *papszPaths)
123{
124 return RTPathFindCommonEx(cPaths, papszPaths, RTPATH_STR_F_STYLE_HOST);
125}
126RT_EXPORT_SYMBOL(RTPathFindCommon);
127
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use