Changeset 83991 in vbox for trunk/src/VBox/Runtime/r3
- Timestamp:
- Apr 27, 2020 10:08:37 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 137558
- Location:
- trunk/src/VBox/Runtime/r3
- Files:
-
- 3 added
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/RTPathTemp.cpp
r83954 r83991 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Path Manipulation .3 * IPRT - Path Manipulation, RTPathTemp. 4 4 */ 5 5 … … 30 30 *********************************************************************************************************************************/ 31 31 #include "internal/iprt.h" 32 #include <iprt/path.h> 33 32 34 #include <iprt/assert.h> 33 35 #include <iprt/env.h> 34 36 #include <iprt/err.h> 35 #include <iprt/path.h>36 37 #include <iprt/string.h> 37 38 #include "internal/path.h" 38 #include "internal/process.h"39 40 41 #ifdef RT_OS_SOLARIS42 /**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 */49 DECLINLINE(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 #endif62 63 64 RTDECL(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 84 RTDECL(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 #else91 return RTPathExecDir(pszPath, cchPath);92 #endif93 }94 95 96 RTDECL(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 #else101 return RTPathExecDir(pszPath, cchPath);102 #endif103 }104 105 106 RTDECL(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 #else115 int rc = RTPathExecDir(pszPath, cchPath);116 return rc;117 #endif118 }119 120 121 RTDECL(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 #else126 return RTPathExecDir(pszPath, cchPath);127 #endif128 }129 130 131 RTDECL(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 #else138 return RTPathExecDir(pszPath, cchPath);139 #endif140 }141 39 142 40 … … 177 75 } 178 76 179 180 RTR3DECL(int) RTPathGetMode(const char *pszPath, PRTFMODE pfMode)181 {182 AssertPtrReturn(pfMode, VERR_INVALID_POINTER);183 184 RTFSOBJINFO ObjInfo;185 int rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_FOLLOW_LINK);186 if (RT_SUCCESS(rc))187 *pfMode = ObjInfo.Attr.fMode;188 189 return rc;190 } -
trunk/src/VBox/Runtime/r3/path.cpp
r82968 r83991 30 30 *********************************************************************************************************************************/ 31 31 #include "internal/iprt.h" 32 #include <iprt/path.h> 33 32 34 #include <iprt/assert.h> 33 #include <iprt/env.h> 34 #include <iprt/err.h> 35 #include <iprt/path.h> 35 #include <iprt/errcore.h> 36 36 #include <iprt/string.h> 37 37 #include "internal/path.h" … … 141 141 142 142 143 RTDECL(int) RTPathTemp(char *pszPath, size_t cchPath)144 {145 /*146 * Try get it from the environment first.147 */148 static const char * const s_apszVars[] =149 {150 "IPRT_TMPDIR"151 #if defined(RT_OS_WINDOWS)152 , "TMP", "TEMP", "USERPROFILE"153 #elif defined(RT_OS_OS2)154 , "TMP", "TEMP", "TMPDIR"155 #else156 , "TMPDIR"157 #endif158 };159 for (size_t iVar = 0; iVar < RT_ELEMENTS(s_apszVars); iVar++)160 {161 int rc = RTEnvGetEx(RTENV_DEFAULT, s_apszVars[iVar], pszPath, cchPath, NULL);162 if (rc != VERR_ENV_VAR_NOT_FOUND)163 return rc;164 }165 166 /*167 * Here we should use some sane system default, instead we just use168 * the typical unix temp dir for now.169 */170 /** @todo Windows should default to the windows directory, see GetTempPath.171 * Some unixes has path.h and _PATH_TMP. There is also a question about172 * whether /var/tmp wouldn't be a better place... */173 if (cchPath < sizeof("/tmp") )174 return VERR_BUFFER_OVERFLOW;175 memcpy(pszPath, "/tmp", sizeof("/tmp"));176 return VINF_SUCCESS;177 }178 179 180 143 RTR3DECL(int) RTPathGetMode(const char *pszPath, PRTFMODE pfMode) 181 144 {
Note:
See TracChangeset
for help on using the changeset viewer.