Changeset 10911 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jul 28, 2008 12:58:44 PM (16 years ago)
- Location:
- trunk/src/VBox/Runtime/r3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/path-posix.cpp
r8256 r10911 982 982 } 983 983 984 985 RTDECL(int) RTPathSetCurrent(const char *pszPath) 986 { 987 /* 988 * Validate input. 989 */ 990 AssertPtrReturn(pszPath, VERR_INVALID_POINTER); 991 AssertReturn(*pszPath, VERR_INVALID_PARAMETER); 992 993 /* 994 * Change the directory. 995 */ 996 char *pszNativePath; 997 int rc = rtPathToNative(&pszNativePath, pszPath); 998 if (RT_SUCCESS(rc)) 999 { 1000 if (chdir(pszNativePath)) 1001 rc = RTErrConvertFromErrno(errno); 1002 RTStrFree(pszNativePath); 1003 } 1004 return rc; 1005 } 1006 -
trunk/src/VBox/Runtime/r3/win/path-win.cpp
r8245 r10911 40 40 #include <iprt/string.h> 41 41 #include <iprt/time.h> 42 #include <iprt/mem.h> 42 43 #include <iprt/param.h> 43 44 #include <iprt/log.h> … … 497 498 } 498 499 500 501 RTDECL(int) RTPathSetCurrent(const char *pszPath) 502 { 503 /* 504 * Validate input. 505 */ 506 AssertPtrReturn(pszPath, VERR_INVALID_POINTER); 507 AssertReturn(*pszPath, VERR_INVALID_PARAMETER); 508 509 /* 510 * This interface is almost identical to the Windows API. 511 */ 512 #ifndef RT_DONT_CONVERT_FILENAMES 513 PRTUTF16 pwszPath; 514 int rc = RTStrToUtf16(pszPath, &pwszPath); 515 if (RT_SUCCESS(rc)) 516 { 517 /** @todo improove the slash stripping a bit? */ 518 size_t cwc = RTUtf16Len(pwszPath); 519 if ( cwc >= 2 520 && ( pwszPath[cwc - 1] == L'/' 521 || pwszPath[cwc - 1] == L'\\') 522 && pwszPath[cwc - 2] != ':') 523 pwszPath[cwc - 1] = L'\0'; 524 525 if (!SetCurrentDirectoryW(pwszPath)) 526 rc = RTErrConvertFromWin32(GetLastError()); 527 528 RTUtf16Free(pwszPath); 529 } 530 #else 531 int rc = VINF_SUCCESS; 532 /** @todo improove the slash stripping a bit? */ 533 char const *pszEnd = strchr(pszPath, '\0'); 534 size_t const cchPath = pszPath - pszEnd; 535 if ( cchPath >= 2 536 && ( pszEnd[-1] == '/' 537 || pszEnd[-1] == '\\') 538 && pszEnd[-2] == ':') 539 { 540 char *pszCopy = (char *)RTMemTmpAlloc(cchPath); 541 if (pszCopy) 542 { 543 memcpy(pszCopy, pszPath, cchPath - 1); 544 pszCopy[cchPath - 1] = '\0'; 545 if (!SetCurrentDirectory(pszCopy)) 546 rc = RTErrConvertFromWin32(GetLastError()); 547 RTMemTmpFree(pszCopy); 548 } 549 else 550 rc = VERR_NO_MEMORY; 551 } 552 else 553 { 554 if (!SetCurrentDirectory(pszPath)) 555 rc = RTErrConvertFromWin32(GetLastError()); 556 } 557 #endif 558 return rc; 559 } 560
Note:
See TracChangeset
for help on using the changeset viewer.