VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/path.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 Id Revision
File size: 4.9 KB
Line 
1/* $Id: path.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Path Manipulation.
4 */
5
6/*
7 * Copyright (C) 2006-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/assert.h>
45#include <iprt/errcore.h>
46#include <iprt/string.h>
47#include "internal/path.h"
48#include "internal/process.h"
49
50
51#ifdef RT_OS_SOLARIS
52/**
53 * Hack to strip of the architecture subdirectory from the exec dir.
54 *
55 * @returns See RTPathExecDir.
56 * @param pszPath See RTPathExecDir.
57 * @param cchPath See RTPathExecDir.
58 */
59DECLINLINE(int) rtPathSolarisArchHack(char *pszPath, size_t cchPath)
60{
61 int rc = RTPathExecDir(pszPath, cchPath);
62 if (RT_SUCCESS(rc))
63 {
64 const char *pszLast = RTPathFilename(pszPath);
65 if ( !strcmp(pszLast, "amd64")
66 || !strcmp(pszLast, "i386"))
67 RTPathStripFilename(pszPath);
68 }
69 return rc;
70}
71#endif
72
73
74RTDECL(int) RTPathExecDir(char *pszPath, size_t cchPath)
75{
76 AssertReturn(g_szrtProcExePath[0], VERR_WRONG_ORDER);
77
78 /*
79 * Calc the length and check if there is space before copying.
80 */
81 size_t cch = g_cchrtProcExeDir;
82 if (cch < cchPath)
83 {
84 memcpy(pszPath, g_szrtProcExePath, cch);
85 pszPath[cch] = '\0';
86 return VINF_SUCCESS;
87 }
88
89 AssertMsgFailed(("Buffer too small (%zu <= %zu)\n", cchPath, cch));
90 return VERR_BUFFER_OVERFLOW;
91}
92
93
94RTDECL(int) RTPathAppPrivateNoArch(char *pszPath, size_t cchPath)
95{
96#if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE)
97 return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE);
98#elif defined(RT_OS_SOLARIS)
99 return rtPathSolarisArchHack(pszPath, cchPath);
100#else
101 return RTPathExecDir(pszPath, cchPath);
102#endif
103}
104
105
106RTDECL(int) RTPathAppPrivateArch(char *pszPath, size_t cchPath)
107{
108#if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE_ARCH)
109 return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE_ARCH);
110#else
111 return RTPathExecDir(pszPath, cchPath);
112#endif
113}
114
115
116RTDECL(int) RTPathAppPrivateArchTop(char *pszPath, size_t cchPath)
117{
118#if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE_ARCH_TOP)
119 return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE_ARCH_TOP);
120#elif !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE_ARCH)
121 return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE_ARCH);
122#elif defined(RT_OS_SOLARIS)
123 return rtPathSolarisArchHack(pszPath, cchPath);
124#else
125 int rc = RTPathExecDir(pszPath, cchPath);
126 return rc;
127#endif
128}
129
130
131RTDECL(int) RTPathSharedLibs(char *pszPath, size_t cchPath)
132{
133#if !defined(RT_OS_WINDOWS) && defined(RTPATH_SHARED_LIBS)
134 return RTStrCopy(pszPath, cchPath, RTPATH_SHARED_LIBS);
135#else
136 return RTPathExecDir(pszPath, cchPath);
137#endif
138}
139
140
141RTDECL(int) RTPathAppDocs(char *pszPath, size_t cchPath)
142{
143#if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_DOCS)
144 return RTStrCopy(pszPath, cchPath, RTPATH_APP_DOCS);
145#elif defined(RT_OS_SOLARIS)
146 return rtPathSolarisArchHack(pszPath, cchPath);
147#else
148 return RTPathExecDir(pszPath, cchPath);
149#endif
150}
151
152
153RTR3DECL(int) RTPathGetMode(const char *pszPath, PRTFMODE pfMode)
154{
155 AssertPtrReturn(pfMode, VERR_INVALID_POINTER);
156
157 RTFSOBJINFO ObjInfo;
158 int rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_FOLLOW_LINK);
159 if (RT_SUCCESS(rc))
160 *pfMode = ObjInfo.Attr.fMode;
161
162 return rc;
163}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use