Changeset 15808 in vbox for trunk/src/VBox
- Timestamp:
- Jan 5, 2009 3:44:53 PM (16 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/path-posix.cpp
r15805 r15808 209 209 * No, prepend the current directory to the relative path. 210 210 */ 211 /** @todo use RTPathGetCurrent */ 212 char szNativeCurDir[PATH_MAX + 1]; 213 if (getcwd(szNativeCurDir, sizeof(szNativeCurDir)) == NULL) 214 { 215 rc = RTErrConvertFromErrno(errno); 216 AssertMsgFailedReturn(("Couldn't get cwd! rc=%Rrc errno=%d\n", rc, errno), rc); 217 } 218 219 char *pszCurDir; 220 rc = rtPathFromNative(&pszCurDir, szNativeCurDir); 221 if (RT_FAILURE(rc)) 222 { 223 LogFlow(("RTPathAbs(%p:{%s}, %p, %d): returns %Rrc\n", pszPath, pszPath, pszAbsPath, cchAbsPath, rc)); 224 return rc; 225 } 226 227 size_t cchCurDir = fsCleanPath(pszCurDir); /* paranoia */ 211 char szCurDir[RTPATH_MAX]; 212 rc = RTPathGetCurrent(szCurDir, sizeof(szCurDir)); 213 AssertRCReturn(rc, rc); 214 215 size_t cchCurDir = fsCleanPath(szCurDir); /* paranoia */ 228 216 if (cchCurDir + cchTmpPath + 1 > PATH_MAX) 229 217 { 230 RTStrFree(pszCurDir);231 218 LogFlow(("RTPathAbs(%p:{%s}, %p, %d): returns %Rrc\n", pszPath, pszPath, pszAbsPath, cchAbsPath, VERR_FILENAME_TOO_LONG)); 232 219 return VERR_FILENAME_TOO_LONG; … … 234 221 235 222 memmove(szTmpPath + cchCurDir + 1, szTmpPath, cchTmpPath + 1); 236 memcpy(szTmpPath, pszCurDir, cchCurDir);223 memcpy(szTmpPath, szCurDir, cchCurDir); 237 224 szTmpPath[cchCurDir] = '/'; 238 225 239 RTStrFree(pszCurDir);240 226 241 227 #ifdef HAVE_DRIVE … … 815 801 816 802 803 RTDECL(int) RTPathGetCurrent(char *pszPath, size_t cchPath) 804 { 805 int rc; 806 char szNativeCurDir[RTPATH_MAX]; 807 if (getcwd(szNativeCurDir, sizeof(szNativeCurDir)) != NULL) 808 { 809 char *pszCurDir; 810 rc = rtPathFromNative(&pszCurDir, szNativeCurDir); 811 if (RT_SUCCESS(rc)) 812 { 813 size_t cchCurDir = strlen(pszCurDir); 814 if (cchCurDir < cchPath) 815 { 816 memcpy(pszPath, pszCurDir, cchCurDir + 1); 817 RTStrFree(pszCurDir); 818 return VINF_SUCCESS; 819 } 820 821 rc = VERR_BUFFER_OVERFLOW; 822 RTStrFree(pszCurDir); 823 } 824 } 825 else 826 rc = RTErrConvertFromErrno(errno); 827 return rc; 828 } 829 830 817 831 RTDECL(int) RTPathSetCurrent(const char *pszPath) 818 832 { -
trunk/src/VBox/Runtime/r3/win/path-win.cpp
r15756 r15808 485 485 486 486 487 RTDECL(int) RTPathGetCurrent(char *pszPath, size_t cchPath) 488 { 489 int rc; 490 491 /* 492 * GetCurrentDirectory may in some cases omit the drive letter, according 493 * to MSDN, thus the GetFullPathName call. 494 */ 495 #ifndef RT_DONT_CONVERT_FILENAMES 496 RTUTF16 wszCurPath[RTPATH_MAX]; 497 if (GetCurrentDirectoryW(RTPATH_MAX, wszCurPath)) 498 { 499 RTUTF16 wszFullPath[RTPATH_MAX]; 500 if (GetFullPathNameW(wszCurPath, RTPATH_MAX, wszFullPath, NULL)) 501 rc = RTUtf16ToUtf8Ex(&wszFullPath[0], RTSTR_MAX, &pszPath, cchPath, NULL); 502 else 503 rc = RTErrConvertFromWin32(GetLastError()); 504 } 505 else 506 rc = RTErrConvertFromWin32(GetLastError()); 507 #else 508 char szCurPath[RTPATH_MAX]; 509 if (GetCurrentDirectory(RTPATH_MAX, szCurPath)) 510 { 511 if (GetFullPathName(szCurPath, cchPath, pszPath, NULL)) 512 rc = VINF_SUCCESS; 513 else 514 rc = RTErrConvertFromWin32(GetLastError()); 515 } 516 else 517 rc = RTErrConvertFromWin32(GetLastError()); 518 #endif 519 return rc; 520 } 521 522 487 523 RTDECL(int) RTPathSetCurrent(const char *pszPath) 488 524 { -
trunk/src/VBox/Runtime/testcase/tstPath.cpp
r15806 r15808 40 40 #include <iprt/param.h> 41 41 42 #if defined (RT_OS_WINDOWS)43 # include <direct.h> // for getcwd44 #else45 # include <unistd.h> // for getcwd46 #endif47 #include <errno.h> // for getcwd48 42 49 43 #define CHECK_RC(method) \ … … 179 173 if (s_aRTPathAbsExTests[i].pcszOutput[0] == '%') 180 174 { 181 /** @todo Use RTPathGetCurrent(). */182 if ( getcwd(szTmp, sizeof(szTmp)) == NULL)175 rc = RTPathGetCurrent(szTmp, sizeof(szTmp)); 176 if (RT_FAILURE(rc)) 183 177 { 184 RTPrintf("tstPath: getcwd failed with errno=%d!\n", errno);178 RTPrintf("tstPath: RTPathGetCurrent failed with rc=%Rrc!\n", rc); 185 179 cErrors++; 186 180 break;
Note:
See TracChangeset
for help on using the changeset viewer.