VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/path.cpp@ 85561

Last change on this file since 85561 was 83991, checked in by vboxsync, 5 years ago

IPRT,VBoxAddInstallNt3x.cpp: Split out the IPRT bits from VBoxAddInstallNt3x.cpp and move template to /Config.kmk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 4.6 KB
Line 
1/* $Id: path.cpp 83991 2020-04-27 10:08:37Z vboxsync $ */
2/** @file
3 * IPRT - Path Manipulation.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "internal/iprt.h"
32#include <iprt/path.h>
33
34#include <iprt/assert.h>
35#include <iprt/errcore.h>
36#include <iprt/string.h>
37#include "internal/path.h"
38#include "internal/process.h"
39
40
41#ifdef RT_OS_SOLARIS
42/**
43 * Hack to strip of the architecture subdirectory from the exec dir.
44 *
45 * @returns See RTPathExecDir.
46 * @param pszPath See RTPathExecDir.
47 * @param cchPath See RTPathExecDir.
48 */
49DECLINLINE(int) rtPathSolarisArchHack(char *pszPath, size_t cchPath)
50{
51 int rc = RTPathExecDir(pszPath, cchPath);
52 if (RT_SUCCESS(rc))
53 {
54 const char *pszLast = RTPathFilename(pszPath);
55 if ( !strcmp(pszLast, "amd64")
56 || !strcmp(pszLast, "i386"))
57 RTPathStripFilename(pszPath);
58 }
59 return rc;
60}
61#endif
62
63
64RTDECL(int) RTPathExecDir(char *pszPath, size_t cchPath)
65{
66 AssertReturn(g_szrtProcExePath[0], VERR_WRONG_ORDER);
67
68 /*
69 * Calc the length and check if there is space before copying.
70 */
71 size_t cch = g_cchrtProcDir;
72 if (cch < cchPath)
73 {
74 memcpy(pszPath, g_szrtProcExePath, cch);
75 pszPath[cch] = '\0';
76 return VINF_SUCCESS;
77 }
78
79 AssertMsgFailed(("Buffer too small (%zu <= %zu)\n", cchPath, cch));
80 return VERR_BUFFER_OVERFLOW;
81}
82
83
84RTDECL(int) RTPathAppPrivateNoArch(char *pszPath, size_t cchPath)
85{
86#if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE)
87 return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE);
88#elif defined(RT_OS_SOLARIS)
89 return rtPathSolarisArchHack(pszPath, cchPath);
90#else
91 return RTPathExecDir(pszPath, cchPath);
92#endif
93}
94
95
96RTDECL(int) RTPathAppPrivateArch(char *pszPath, size_t cchPath)
97{
98#if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE_ARCH)
99 return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE_ARCH);
100#else
101 return RTPathExecDir(pszPath, cchPath);
102#endif
103}
104
105
106RTDECL(int) RTPathAppPrivateArchTop(char *pszPath, size_t cchPath)
107{
108#if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE_ARCH_TOP)
109 return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE_ARCH_TOP);
110#elif !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE_ARCH)
111 return RTStrCopy(pszPath, cchPath, RTPATH_APP_PRIVATE_ARCH);
112#elif defined(RT_OS_SOLARIS)
113 return rtPathSolarisArchHack(pszPath, cchPath);
114#else
115 int rc = RTPathExecDir(pszPath, cchPath);
116 return rc;
117#endif
118}
119
120
121RTDECL(int) RTPathSharedLibs(char *pszPath, size_t cchPath)
122{
123#if !defined(RT_OS_WINDOWS) && defined(RTPATH_SHARED_LIBS)
124 return RTStrCopy(pszPath, cchPath, RTPATH_SHARED_LIBS);
125#else
126 return RTPathExecDir(pszPath, cchPath);
127#endif
128}
129
130
131RTDECL(int) RTPathAppDocs(char *pszPath, size_t cchPath)
132{
133#if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_DOCS)
134 return RTStrCopy(pszPath, cchPath, RTPATH_APP_DOCS);
135#elif defined(RT_OS_SOLARIS)
136 return rtPathSolarisArchHack(pszPath, cchPath);
137#else
138 return RTPathExecDir(pszPath, cchPath);
139#endif
140}
141
142
143RTR3DECL(int) RTPathGetMode(const char *pszPath, PRTFMODE pfMode)
144{
145 AssertPtrReturn(pfMode, VERR_INVALID_POINTER);
146
147 RTFSOBJINFO ObjInfo;
148 int rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_FOLLOW_LINK);
149 if (RT_SUCCESS(rc))
150 *pfMode = ObjInfo.Attr.fMode;
151
152 return rc;
153}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette