Changeset 20101 in vbox
- Timestamp:
- May 27, 2009 4:43:08 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 47851
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/path.cpp
r20019 r20101 964 964 } 965 965 966 966 967 /** 967 968 * Gets the temporary directory path. 968 969 * 969 970 * @returns iprt status code. 971 * 970 972 * @param pszPath Buffer where to store the path. 971 973 * @param cchPath Buffer size in bytes. … … 973 975 RTDECL(int) RTPathTemp(char *pszPath, size_t cchPath) 974 976 { 975 int rc; 976 const char *pszTmpEnv = RTEnvGet("TMP"); 977 if (!pszTmpEnv) 978 pszTmpEnv = RTEnvGet("TEMP"); 979 char *pszTmpDir; 980 /* Make a copy in any case. */ 981 if (pszTmpEnv) 982 pszTmpDir = RTStrDup(pszTmpEnv); 983 else 984 pszTmpDir = RTStrDup("/tmp"); 985 986 size_t cchTmpDir = strlen(pszTmpDir); 987 if (cchTmpDir < cchPath) 988 memcpy(pszPath, pszTmpDir, cchTmpDir + 1); 989 else 990 rc = VERR_BUFFER_OVERFLOW; 991 RTStrFree(pszTmpDir); 992 return rc; 977 /* 978 * Try get it from the environment first. 979 */ 980 static const char * const s_apszVars[] = 981 { 982 "IPRT_TMPDIR" 983 #if defined(RT_OS_WINDOWS) 984 , "TMP", "TEMP", "USERPROFILE" 985 #elif defined(RT_OS_OS2) 986 , "TMP", "TEMP", "TMPDIR" 987 #else 988 , "TMPDIR" 989 #endif 990 }; 991 for (size_t iVar = 0; iVar < RT_ELEMENTS(s_apszVars); iVar++) 992 { 993 int rc = RTEnvGetEx(RTENV_DEFAULT, s_apszVars[iVar], pszPath, cchPath, NULL); 994 if (rc != VERR_ENV_VAR_NOT_FOUND) 995 return rc; 996 } 997 998 /* 999 * Here we should use some sane system default, instead we just use 1000 * the typical unix temp dir for now. 1001 */ 1002 /** @todo Windows should default to the windows directory, see GetTempPath. 1003 * Some unixes has path.h and _PATH_TMP. There is also a question about 1004 * whether /var/tmp wouldn't be a better place... */ 1005 if (cchPath < sizeof("/tmp") ) 1006 return VERR_BUFFER_OVERFLOW; 1007 memcpy(pszPath, "/tmp", sizeof("/tmp")); 1008 return VINF_SUCCESS; 993 1009 } 994 1010 -
trunk/src/VBox/Runtime/testcase/tstPath.cpp
r19929 r20101 78 78 if (RT_SUCCESS(rc)) 79 79 RTTestIPrintf(RTTESTLVL_INFO, "UserHome={%s}\n", szPath); 80 81 RTTestSub(hTest, "RTPathTemp"); 82 RTTESTI_CHECK_RC(RTPathTemp(szPath, sizeof(szPath)), VINF_SUCCESS); 83 if (RT_SUCCESS(rc)) 84 RTTestIPrintf(RTTESTLVL_INFO, "PathTemp={%s}\n", szPath); 85 size_t cch = strlen(szPath); 86 RTTESTI_CHECK_RC(RTPathTemp(szPath, cch), VERR_BUFFER_OVERFLOW); 87 RTTESTI_CHECK_RC(RTPathTemp(szPath, cch+1), VINF_SUCCESS); 88 RTTESTI_CHECK_RC(RTPathTemp(szPath, cch+2), VINF_SUCCESS); 89 80 90 81 91 /*
Note:
See TracChangeset
for help on using the changeset viewer.