Changeset 28918 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Apr 29, 2010 6:30:09 PM (15 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/include/internal/dir.h
r28917 r28918 75 75 /** Set to indicate that the Data member contains unread data. */ 76 76 bool fDataUnread; 77 #ifndef RT_DONT_CONVERT_FILENAMES78 77 /** Pointer to the converted filename. 79 78 * This can be NULL. */ … … 85 84 /** The length of the converted filename. */ 86 85 size_t cchName; 87 #endif88 86 89 87 #ifdef RT_OS_WINDOWS … … 92 90 /** Find data buffer. 93 91 * fDataUnread indicates valid data. */ 94 # ifdef RT_DONT_CONVERT_FILENAMES95 WIN32_FIND_DATAA Data;96 # else97 92 WIN32_FIND_DATAW Data; 98 # endif99 93 100 94 #else /* 'POSIX': */ -
trunk/src/VBox/Runtime/r3/dir.cpp
r28915 r28918 637 637 Assert(pb - (uint8_t *)pDir + cchRealPath + 1 <= cbAllocated); 638 638 pDir->fDataUnread = false; 639 #ifndef RT_DONT_CONVERT_FILENAMES640 639 pDir->pszName = NULL; 641 640 pDir->cchName = 0; 642 #endif643 641 #ifndef RT_OS_WINDOWS 644 642 pDir->cbMaxName = cbDir - RT_OFFSETOF(RTDIR, Data.d_name); -
trunk/src/VBox/Runtime/r3/posix/dir-posix.cpp
r28915 r28918 261 261 } 262 262 263 #ifndef RT_DONT_CONVERT_FILENAMES264 263 /* 265 264 * Convert the filename to UTF-8. … … 279 278 break; 280 279 rtPathFreeIprt(pDir->pszName, pDir->Data.d_name); 281 pDir->pszName = NULL; 282 #else 283 if ( !pDir->pfnFilter 284 || pDir->pfnFilter(pDir, pDir->Data.d_name)) 285 break; 286 #endif 280 pDir->pszName = NULL; 287 281 pDir->fDataUnread = false; 288 282 } … … 349 343 * Check if we've got enough space to return the data. 350 344 */ 351 #ifdef RT_DONT_CONVERT_FILENAMES352 const char *pszName = pDir->Data.d_name;353 const size_t cchName = strlen(pszName);354 #else355 345 const char *pszName = pDir->pszName; 356 346 const size_t cchName = pDir->cchName; 357 #endif358 347 const size_t cbRequired = RT_OFFSETOF(RTDIRENTRY, szName[1]) + cchName; 359 348 if (pcbDirEntry) … … 376 365 /* free cached data */ 377 366 pDir->fDataUnread = false; 378 #ifndef RT_DONT_CONVERT_FILENAMES379 367 rtPathFreeIprt(pDir->pszName, pDir->Data.d_name); 380 368 pDir->pszName = NULL; 381 #endif382 369 } 383 370 else … … 457 444 * Check if we've got enough space to return the data. 458 445 */ 459 #ifdef RT_DONT_CONVERT_FILENAMES460 const char *pszName = pDir->Data.d_name;461 const size_t cchName = strlen(pszName);462 #else463 446 const char *pszName = pDir->pszName; 464 447 const size_t cchName = pDir->cchName; 465 #endif466 448 const size_t cbRequired = RT_OFFSETOF(RTDIRENTRYEX, szName[1]) + cchName; 467 449 if (pcbDirEntry) … … 501 483 /* free cached data */ 502 484 pDir->fDataUnread = false; 503 #ifndef RT_DONT_CONVERT_FILENAMES504 485 rtPathFreeIprt(pDir->pszName, pDir->Data.d_name); 505 486 pDir->pszName = NULL; 506 #endif507 487 } 508 488 else -
trunk/src/VBox/Runtime/r3/posix/fileio-posix.cpp
r28915 r28918 75 75 * Defined Constants And Macros * 76 76 *******************************************************************************/ 77 /** @def RT_DONT_CONVERT_FILENAMES78 * Define this to pass UTF-8 unconverted to the kernel. */79 #ifdef DOXYGEN_RUNNING80 #define RT_DONT_CONVERT_FILENAMES 181 #endif82 83 77 /** Default file permissions for newly created files. */ 84 78 #if defined(S_IRUSR) && defined(S_IWUSR) … … 201 195 * Open/create the file. 202 196 */ 203 #ifdef RT_DONT_CONVERT_FILENAMES204 int fh = open(pszFilename, fOpenMode, fMode);205 int iErr = errno;206 #else207 197 char const *pszNativeFilename; 208 198 rc = rtPathToNative(&pszNativeFilename, pszFilename, NULL); … … 213 203 int iErr = errno; 214 204 rtPathFreeNative(pszNativeFilename, pszFilename); 215 #endif216 205 if (fh >= 0) 217 206 { -
trunk/src/VBox/Runtime/r3/win/dir-win.cpp
r28915 r28918 160 160 */ 161 161 int rc = VINF_SUCCESS; 162 #ifndef RT_DONT_CONVERT_FILENAMES163 162 PRTUTF16 pwszName; 164 163 rc = RTStrToUtf16(pszPathBuf, &pwszName); … … 166 165 { 167 166 pDir->hDir = FindFirstFileW((LPCWSTR)pwszName, &pDir->Data); 168 #else169 pDir->hDir = FindFirstFileA(pszPathBuf, &pDir->Data);170 #endif171 167 if (pDir->hDir != INVALID_HANDLE_VALUE) 172 168 pDir->fDataUnread = true; … … 176 172 else 177 173 rc = RTErrConvertFromWin32(GetLastError()); 178 #ifndef RT_DONT_CONVERT_FILENAMES179 174 RTUtf16Free(pwszName); 180 175 } 181 #endif182 176 183 177 return rc; … … 247 241 if (!pDir->fDataUnread) 248 242 { 249 #ifdef RT_DONT_CONVERT_FILENAMES250 BOOL fRc = FindNextFileA(pDir->hDir, &pDir->Data);251 252 #else253 243 RTStrFree(pDir->pszName); 254 244 pDir->pszName = NULL; 255 245 256 246 BOOL fRc = FindNextFileW(pDir->hDir, &pDir->Data); 257 #endif258 247 if (!fRc) 259 248 { … … 265 254 } 266 255 267 #ifndef RT_DONT_CONVERT_FILENAMES268 256 /* 269 257 * Convert the filename to UTF-8. … … 279 267 pDir->cchName = strlen(pDir->pszName); 280 268 } 281 #endif282 269 283 270 /* 284 271 * Check if we've got enough space to return the data. 285 272 */ 286 #ifdef RT_DONT_CONVERT_FILENAMES287 const char *pszName = pDir->Data.cName;288 const size_t cchName = strlen(pszName);289 #else290 273 const char *pszName = pDir->pszName; 291 274 const size_t cchName = pDir->cchName; 292 #endif293 275 const size_t cbRequired = RT_OFFSETOF(RTDIRENTRY, szName[1]) + cchName; 294 276 if (pcbDirEntry) … … 352 334 if (!pDir->fDataUnread) 353 335 { 354 #ifdef RT_DONT_CONVERT_FILENAMES355 BOOL fRc = FindNextFileA(pDir->hDir, &pDir->Data);356 357 #else358 336 RTStrFree(pDir->pszName); 359 337 pDir->pszName = NULL; 360 338 361 339 BOOL fRc = FindNextFileW(pDir->hDir, &pDir->Data); 362 #endif363 340 if (!fRc) 364 341 { … … 370 347 } 371 348 372 #ifndef RT_DONT_CONVERT_FILENAMES373 349 /* 374 350 * Convert the filename to UTF-8. … … 384 360 pDir->cchName = strlen(pDir->pszName); 385 361 } 386 #endif387 362 388 363 /* 389 364 * Check if we've got enough space to return the data. 390 365 */ 391 #ifdef RT_DONT_CONVERT_FILENAMES392 const char *pszName = pDir->Data.cName;393 const size_t cchName = strlen(pszName);394 #else395 366 const char *pszName = pDir->pszName; 396 367 const size_t cchName = pDir->cchName; 397 #endif398 368 const size_t cbRequired = RT_OFFSETOF(RTDIRENTRYEX, szName[1]) + cchName; 399 369 if (pcbDirEntry) … … 409 379 Assert(pDirEntry->cbName == cchName); 410 380 memcpy(pDirEntry->szName, pszName, cchName + 1); 411 #ifndef RT_DONT_CONVERT_FILENAMES /* this ain't nice since the whole point of this define is not to drag in conversion... */412 381 if (pDir->Data.cAlternateFileName[0]) 413 382 { … … 424 393 } 425 394 else 426 #endif427 395 { 428 396 memset(pDirEntry->wszShortName, 0, sizeof(pDirEntry->wszShortName)); -
trunk/src/VBox/Runtime/r3/win/fileio-win.cpp
r28800 r28918 46 46 * Defined Constants And Macros * 47 47 *******************************************************************************/ 48 /** @def RT_DONT_CONVERT_FILENAMES49 * Define this to pass UTF-8 unconverted to the kernel. */50 #ifdef DOXYGEN_RUNNING51 # define RT_DONT_CONVERT_FILENAMES 152 #endif53 48 54 49 … … 280 275 * Open/Create the file. 281 276 */ 282 #ifdef RT_DONT_CONVERT_FILENAMES283 HANDLE hFile = CreateFile(pszFilename,284 dwDesiredAccess,285 dwShareMode,286 pSecurityAttributes,287 dwCreationDisposition,288 dwFlagsAndAttributes,289 NULL);290 #else291 277 PRTUTF16 pwszFilename; 292 278 rc = RTStrToUtf16(pszFilename, &pwszFilename); … … 301 287 dwFlagsAndAttributes, 302 288 NULL); 303 #endif304 289 if (hFile != INVALID_HANDLE_VALUE) 305 290 { … … 314 299 && (fOpen & RTFILE_O_NOT_CONTENT_INDEXED)) 315 300 { 316 #ifdef RT_DONT_CONVERT_FILENAMES317 if (!SetFileAttributes(pszFilename, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))318 #else319 301 if (!SetFileAttributesW(pwszFilename, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)) 320 #endif321 302 rc = RTErrConvertFromWin32(GetLastError()); 322 303 } … … 335 316 *pFile = (RTFILE)hFile; 336 317 Assert((HANDLE)*pFile == hFile); 337 #ifndef RT_DONT_CONVERT_FILENAMES338 318 RTUtf16Free(pwszFilename); 339 #endif340 319 return VINF_SUCCESS; 341 320 } … … 345 324 else 346 325 rc = RTErrConvertFromWin32(GetLastError()); 347 #ifndef RT_DONT_CONVERT_FILENAMES348 326 RTUtf16Free(pwszFilename); 349 #endif350 327 return rc; 351 328 } … … 805 782 RTR3DECL(int) RTFileDelete(const char *pszFilename) 806 783 { 807 #ifdef RT_DONT_CONVERT_FILENAMES808 if (DeleteFile(pszFilename))809 return VINF_SUCCESS;810 return RTErrConvertFromWin32(GetLastError());811 812 #else813 784 PRTUTF16 pwszFilename; 814 785 int rc = RTStrToUtf16(pszFilename, &pwszFilename); … … 821 792 822 793 return rc; 823 #endif824 794 } 825 795 -
trunk/src/VBox/Runtime/r3/win/fs-win.cpp
r28800 r28918 86 86 87 87 88 #ifndef RT_DONT_CONVERT_FILENAMES89 88 90 89 /** … … 155 154 } 156 155 157 #else /* RT_DONT_CONVERT_FILENAMES */158 159 /**160 * Finds the root of the specified volume.161 *162 * @returns iprt status code.163 * @param pszFsPath Path within the filesystem. Verified as one byte or more.164 * @param ppszFsRoot Where to store the returned string. Free with rtFsFreeRoot(),165 */166 static int rtFsGetRoot(const char *pszFsPath, char **ppszFsRoot)167 {168 /*169 * Do straight forward stuff first,170 */171 if (rtFsIsRoot(pszFsPath))172 return RTStrDupEx(ppszFsRoot, pszFsPath);173 174 /*175 * Expand and add slash (if required).176 */177 char szFullPath[RTPATH_MAX];178 int rc = RTPathAbs(pszFsPath, szFullPath, sizeof(szFullPath));179 if (RT_FAILURE(rc))180 return rc;181 size_t cb = strlen(szFullPath);182 if (!RTPATH_IS_SLASH(szFullPath[cb - 1]))183 {184 AssertReturn(cb + 1 < RTPATH_MAX);185 szFullPath[cb] = '\\';186 szFullPath[++cb] = '\0';187 }188 189 /*190 * Walk the path until our proper API is happy or there is no more path left.191 */192 if (GetVolumeInformation(szFullPath, NULL, 0, NULL, NULL, 0, NULL, 0))193 {194 char *pszEnd = szFullPath + cb;195 char *pszMin = szFullPath + 2;196 do197 {198 /* Strip off the last path component. */199 while (pszEnd-- > pszMin)200 if (RTPATH_IS_SLASH(*pszEnd))201 break;202 AssertReturn(pszEnd >= pszMin, VERR_INTERNAL_ERROR);203 pszEnd[1] = '\0';204 } while (GetVolumeInformationA(pszStart, NULL, 0, NULL, NULL, 0, NULL, 0));205 }206 207 return RTStrDupEx(ppszFsRoot, szFullPath);208 }209 210 /**211 * Frees string returned by rtFsGetRoot().212 */213 static void rtFsFreeRoot(char *pszFsRoot)214 {215 RTStrFree(pszFsRoot);216 }217 218 #endif /* RT_DONT_CONVERT_FILENAMES*/219 220 156 221 157 RTR3DECL(int) RTFsQuerySizes(const char *pszFsPath, RTFOFF *pcbTotal, RTFOFF *pcbFree, … … 226 162 */ 227 163 AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER); 228 #ifndef RT_DONT_CONVERT_FILENAMES229 164 PRTUTF16 pwszFsRoot; 230 165 int rc = rtFsGetRoot(pszFsPath, &pwszFsRoot); 231 #else232 char pszFsRoot;233 int rc = rtFsGetRoot(pszFsPath, &pszFsRoot);234 #endif235 166 if (RT_FAILURE(rc)) 236 167 return rc; … … 243 174 ULARGE_INTEGER cbTotal; 244 175 ULARGE_INTEGER cbFree; 245 #ifndef RT_DONT_CONVERT_FILENAMES246 176 if (GetDiskFreeSpaceExW(pwszFsRoot, &cbFree, &cbTotal, NULL)) 247 #else248 if (GetDiskFreeSpaceExA(pszFsRoot, &cbFree, &cbTotal, NULL))249 #endif250 177 { 251 178 if (pcbTotal) … … 272 199 DWORD cbSector; 273 200 DWORD cSectorsPerCluster; 274 #ifndef RT_DONT_CONVERT_FILENAMES275 201 if (GetDiskFreeSpaceW(pwszFsRoot, &cSectorsPerCluster, &cbSector, &dwDummy1, &dwDummy2)) 276 #else277 if (GetDiskFreeSpaceA(pszFsRoot, &cSectorsPerCluster, &cbSector, &dwDummy1, &dwDummy2))278 #endif279 202 { 280 203 if (pcbBlock) … … 292 215 } 293 216 294 #ifndef RT_DONT_CONVERT_FILENAMES295 217 rtFsFreeRoot(pwszFsRoot); 296 #else297 rtFsFreeRoot(pszFsRoot);298 #endif299 218 return rc; 300 219 } … … 315 234 AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER); 316 235 AssertMsgReturn(VALID_PTR(pu32Serial), ("%p", pu32Serial), VERR_INVALID_PARAMETER); 317 #ifndef RT_DONT_CONVERT_FILENAMES318 236 PRTUTF16 pwszFsRoot; 319 237 int rc = rtFsGetRoot(pszFsPath, &pwszFsRoot); 320 #else321 char pszFsRoot;322 int rc = rtFsGetRoot(pszFsPath, &pszFsRoot);323 #endif324 238 if (RT_FAILURE(rc)) 325 239 return rc; … … 331 245 DWORD dwFlags; 332 246 DWORD dwSerial; 333 #ifndef RT_DONT_CONVERT_FILENAMES334 247 if (GetVolumeInformationW(pwszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0)) 335 #else336 if (GetVolumeInformationA(pszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0))337 #endif338 248 *pu32Serial = dwSerial; 339 249 else … … 345 255 } 346 256 347 #ifndef RT_DONT_CONVERT_FILENAMES348 257 RTUtf16Free(pwszFsRoot); 349 #else350 RTStrFree(pszFsRoot);351 #endif352 258 return rc; 353 259 } … … 368 274 AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER); 369 275 AssertMsgReturn(VALID_PTR(pProperties), ("%p", pProperties), VERR_INVALID_PARAMETER); 370 #ifndef RT_DONT_CONVERT_FILENAMES371 276 PRTUTF16 pwszFsRoot; 372 277 int rc = rtFsGetRoot(pszFsPath, &pwszFsRoot); 373 #else374 char pszFsRoot;375 int rc = rtFsGetRoot(pszFsPath, &pszFsRoot);376 #endif377 278 if (RT_FAILURE(rc)) 378 279 return rc; … … 384 285 DWORD dwFlags; 385 286 DWORD dwSerial; 386 #ifndef RT_DONT_CONVERT_FILENAMES387 287 if (GetVolumeInformationW(pwszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0)) 388 #else389 if (GetVolumeInformationA(pszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0))390 #endif391 288 { 392 289 memset(pProperties, 0, sizeof(*pProperties)); … … 407 304 } 408 305 409 #ifndef RT_DONT_CONVERT_FILENAMES410 306 RTUtf16Free(pwszFsRoot); 411 #else412 RTStrFree(pszFsRoot);413 #endif414 307 return rc; 415 308 } -
trunk/src/VBox/Runtime/r3/win/path-win.cpp
r28800 r28918 206 206 */ 207 207 WIN32_FILE_ATTRIBUTE_DATA Data; 208 #ifndef RT_DONT_CONVERT_FILENAMES209 208 PRTUTF16 pwszPath; 210 209 int rc = RTStrToUtf16(pszPath, &pwszPath); … … 240 239 } 241 240 RTUtf16Free(pwszPath); 242 #else243 if (!GetFileAttributesExA(pszPath, GetFileExInfoStandard, &Data))244 {245 /* Fallback to FindFileFirst in case of sharing violation. */246 if (GetLastError() != ERROR_SHARING_VIOLATION)247 return RTErrConvertFromWin32(GetLastError());248 WIN32_FIND_DATAA FindData;249 HANDLE hDir = FindFirstFileA(pszPath, &FindData);250 if (hDir == INVALID_HANDLE_VALUE)251 return RTErrConvertFromWin32(GetLastError());252 FindClose(hDir);253 Data.dwFileAttributes = FindData.dwFileAttributes;254 Data.ftCreationTime = FindData.ftCreationTime;255 Data.ftLastAccessTime = FindData.ftLastAccessTime;256 Data.ftLastWriteTime = FindData.ftLastWriteTime;257 Data.nFileSizeHigh = FindData.nFileSizeHigh;258 Data.nFileSizeLow = FindData.nFileSizeLow;259 }260 #endif261 241 if ( (fFlags & RTPATH_F_FOLLOW_LINK) 262 242 && (Data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) … … 538 518 */ 539 519 DWORD dwAttr; 540 #ifndef RT_DONT_CONVERT_FILENAMES541 520 PRTUTF16 pwszPath; 542 521 int rc = RTStrToUtf16(pszPath, &pwszPath); … … 548 527 else 549 528 dwAttr = INVALID_FILE_ATTRIBUTES; 550 #else551 dwAttr = GetFileAttributesA(pszPath);552 #endif553 554 529 if (dwAttr == INVALID_FILE_ATTRIBUTES) 555 530 return false; … … 577 552 * to MSDN, thus the GetFullPathName call. 578 553 */ 579 #ifndef RT_DONT_CONVERT_FILENAMES580 554 RTUTF16 wszCurPath[RTPATH_MAX]; 581 555 if (GetCurrentDirectoryW(RTPATH_MAX, wszCurPath)) … … 589 563 else 590 564 rc = RTErrConvertFromWin32(GetLastError()); 591 #else592 char szCurPath[RTPATH_MAX];593 if (GetCurrentDirectory(RTPATH_MAX, szCurPath))594 {595 if (GetFullPathName(szCurPath, cchPath, pszPath, NULL))596 rc = VINF_SUCCESS;597 else598 rc = RTErrConvertFromWin32(GetLastError());599 }600 else601 rc = RTErrConvertFromWin32(GetLastError());602 #endif603 565 return rc; 604 566 } … … 616 578 * This interface is almost identical to the Windows API. 617 579 */ 618 #ifndef RT_DONT_CONVERT_FILENAMES619 580 PRTUTF16 pwszPath; 620 581 int rc = RTStrToUtf16(pszPath, &pwszPath); 621 582 if (RT_SUCCESS(rc)) 622 583 { 623 /** @todo impro ove the slash stripping a bit? */584 /** @todo improve the slash stripping a bit? */ 624 585 size_t cwc = RTUtf16Len(pwszPath); 625 586 if ( cwc >= 2 … … 634 595 RTUtf16Free(pwszPath); 635 596 } 636 #else 637 int rc = VINF_SUCCESS; 638 /** @todo improove the slash stripping a bit? */ 639 char const *pszEnd = strchr(pszPath, '\0'); 640 size_t const cchPath = pszPath - pszEnd; 641 if ( cchPath >= 2 642 && ( pszEnd[-1] == '/' 643 || pszEnd[-1] == '\\') 644 && pszEnd[-2] == ':') 645 { 646 char *pszCopy = (char *)RTMemTmpAlloc(cchPath); 647 if (pszCopy) 648 { 649 memcpy(pszCopy, pszPath, cchPath - 1); 650 pszCopy[cchPath - 1] = '\0'; 651 if (!SetCurrentDirectory(pszCopy)) 652 rc = RTErrConvertFromWin32(GetLastError()); 653 RTMemTmpFree(pszCopy); 654 } 655 else 656 rc = VERR_NO_MEMORY; 657 } 658 else 659 { 660 if (!SetCurrentDirectory(pszPath)) 661 rc = RTErrConvertFromWin32(GetLastError()); 662 } 663 #endif 664 return rc; 665 } 666 597 return rc; 598 } 599
Note:
See TracChangeset
for help on using the changeset viewer.