Changeset 96077 in vbox
- Timestamp:
- Aug 6, 2022 1:58:08 AM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 152876
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/stream.h
r95977 r96077 127 127 */ 128 128 RTR3DECL(int) RTStrmOpenF(const char *pszMode, PRTSTREAM *ppStream, const char *pszFilenameFmt, ...) RT_IPRT_FORMAT_ATTR(3, 4); 129 130 /** 131 * Opens a file stream for a RTFILE handle, taking ownership of the handle. 132 * 133 * @returns iprt status code. 134 * @param hFile The file handle to use. On success, handle 135 * ownership is transfered to the stream and it will be 136 * closed when the stream closes. 137 * @param pszMode The open mode, accept the same as RTStrOpen and 138 * friends however it is only used to figure out what 139 * we can do with the handle. 140 * @param fFlags Reserved, must be zero. 141 * @param ppStream Where to store the opened stream. 142 */ 143 RTR3DECL(int) RTStrmOpenFileHandle(RTFILE hFile, const char *pszMode, uint32_t fFlags, PRTSTREAM *ppStream); 129 144 130 145 /** -
trunk/src/VBox/Runtime/r3/stream.cpp
r95980 r96077 408 408 * 409 409 * @returns iprt status code. 410 * @param pszFilename Path to the file to open. 411 * @param pszMode The open mode. See fopen() standard. 412 * Format: <a|r|w>[+][b|t][x][e|N|E] 413 * - 'a': Open or create file and writes 414 * append tos it. 415 * - 'r': Open existing file and read from it. 416 * - 'w': Open or truncate existing file and write 417 * to it. 418 * - '+': Open for both read and write access. 419 * - 'b' / 't': binary / text 420 * - 'x': exclusively create, no open. Only 421 * possible with 'w'. 422 * - 'e' / 'N': No inherit on exec. (The 'e' is 423 * how Linux and FreeBSD expresses this, the 424 * latter is Visual C++). 410 * @param pszFilename Path to the file to open, hFile must be NIL_RTFILE. 411 * NULL if a hFile is to be used instead. 412 * @param hFile File handle to use when called from 413 * RTStrmOpenFileHandle. pszFilename must be NULL. 414 * @param pszMode See RTStrmOpen. 425 415 * @param ppStream Where to store the opened stream. 426 416 */ 427 RTR3DECL(int) RTStrmOpen(const char *pszFilename, const char *pszMode, PRTSTREAM *ppStream)417 static int rtStrmOpenComon(const char *pszFilename, RTFILE hFile, const char *pszMode, PRTSTREAM *ppStream) 428 418 { 429 419 /* … … 431 421 */ 432 422 AssertReturn(pszMode && *pszMode, VERR_INVALID_FLAGS); 433 AssertReturn(pszFilename, VERR_INVALID_PARAMETER);434 423 435 424 /* … … 551 540 pStream->pCritSect = NULL; 552 541 #endif 553 RTFILE hFile = NIL_RTFILE;554 542 RTFILEACTION enmActionTaken = RTFILEACTION_INVALID; 555 rc = RTFileOpenEx(pszFilename, fOpen, &hFile, &enmActionTaken); 543 if (pszFilename) 544 rc = RTFileOpenEx(pszFilename, fOpen, &hFile, &enmActionTaken); 545 else 546 rc = VINF_SUCCESS; 556 547 if (RT_SUCCESS(rc)) 557 548 { … … 594 585 close(fd); 595 586 hFile = NIL_RTFILE; 587 /** @todo we're in trouble here when called from RTStrmOpenFileHandle! */ 596 588 # endif 597 589 } … … 604 596 # endif 605 597 } 606 RTFileClose(hFile); 607 if (enmActionTaken == RTFILEACTION_CREATED) 608 RTFileDelete(pszFilename); 598 if (pszFilename) 599 { 600 RTFileClose(hFile); 601 if (enmActionTaken == RTFILEACTION_CREATED) 602 RTFileDelete(pszFilename); 603 } 609 604 #endif 610 605 } … … 612 607 } 613 608 return rc; 609 } 610 611 612 /** 613 * Opens a file stream. 614 * 615 * @returns iprt status code. 616 * @param pszFilename Path to the file to open. 617 * @param pszMode The open mode. See fopen() standard. 618 * Format: <a|r|w>[+][b|t][x][e|N|E] 619 * - 'a': Open or create file and writes 620 * append tos it. 621 * - 'r': Open existing file and read from it. 622 * - 'w': Open or truncate existing file and write 623 * to it. 624 * - '+': Open for both read and write access. 625 * - 'b' / 't': binary / text 626 * - 'x': exclusively create, no open. Only 627 * possible with 'w'. 628 * - 'e' / 'N': No inherit on exec. (The 'e' is 629 * how Linux and FreeBSD expresses this, the 630 * latter is Visual C++). 631 * @param ppStream Where to store the opened stream. 632 */ 633 RTR3DECL(int) RTStrmOpen(const char *pszFilename, const char *pszMode, PRTSTREAM *ppStream) 634 { 635 *ppStream = NULL; 636 AssertReturn(pszFilename, VERR_INVALID_PARAMETER); 637 return rtStrmOpenComon(pszFilename, NIL_RTFILE, pszMode, ppStream); 614 638 } 615 639 … … 658 682 va_end(args); 659 683 return rc; 684 } 685 686 687 /** 688 * Opens a file stream for a RTFILE handle, taking ownership of the handle. 689 * 690 * @returns iprt status code. 691 * @param hFile The file handle to use. On success, handle 692 * ownership is transfered to the stream and it will be 693 * closed when the stream closes. 694 * @param pszMode The open mode, accept the same as RTStrOpen and 695 * friends however it is only used to figure out what 696 * we can do with the handle. 697 * @param fFlags Reserved, must be zero. 698 * @param ppStream Where to store the opened stream. 699 */ 700 RTR3DECL(int) RTStrmOpenFileHandle(RTFILE hFile, const char *pszMode, uint32_t fFlags, PRTSTREAM *ppStream) 701 { 702 *ppStream = NULL; 703 AssertReturn(RTFileIsValid(hFile), VERR_INVALID_HANDLE); 704 AssertReturn(fFlags == 0, VERR_INVALID_FLAGS); 705 return rtStrmOpenComon(NULL, hFile, pszMode, ppStream); 660 706 } 661 707
Note:
See TracChangeset
for help on using the changeset viewer.