Changeset 75045 in vbox
- Timestamp:
- Oct 24, 2018 2:46:53 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 126088
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/file.h
r69977 r75045 1131 1131 #define RTFILE_RDALL_O_DENY_NOT_DELETE RTFILE_O_DENY_NOT_DELETE 1132 1132 #define RTFILE_RDALL_O_DENY_MASK RTFILE_O_DENY_MASK 1133 /** Fail with VERR_OUT_OF_RANGE if the file size exceeds the specified maximum 1134 * size. The default behavior is to cap the size at cbMax. */ 1135 #define RTFILE_RDALL_F_FAIL_ON_MAX_SIZE RT_BIT_32(30) 1133 1136 /** Add a trailing zero byte to facilitate reading text files. */ 1134 1137 #define RTFILE_RDALL_F_TRAILING_ZERO_BYTE RT_BIT_32(31) 1135 1138 /** Mask of valid flags. */ 1136 #define RTFILE_RDALL_VALID_MASK (RTFILE_RDALL_O_DENY_MASK | UINT32_C(0x 80000000))1139 #define RTFILE_RDALL_VALID_MASK (RTFILE_RDALL_O_DENY_MASK | UINT32_C(0xc0000000)) 1137 1140 /** @} */ 1138 1141 -
trunk/src/VBox/Runtime/generic/RTFileReadAllByHandleEx-generic.cpp
r69111 r75045 53 53 */ 54 54 RTFOFF cbFile; 55 rc = RTFileSeek(File, 0,RTFILE_SEEK_END, (uint64_t *)&cbFile); 55 AssertCompile(sizeof(cbFile) == sizeof(uint64_t)); 56 rc = RTFileSeek(File, 0, RTFILE_SEEK_END, (uint64_t *)&cbFile); 56 57 if (RT_SUCCESS(rc)) 57 58 { 58 59 RTFOFF cbAllocFile = cbFile > off ? cbFile - off : 0; 59 if (cbAllocFile > cbMax) 60 if (cbAllocFile <= cbMax) 61 { /* likely */ } 62 else if (!(fFlags & RTFILE_RDALL_F_FAIL_ON_MAX_SIZE)) 60 63 cbAllocFile = cbMax; 61 size_t cbAllocMem = (size_t)cbAllocFile; 62 if ((RTFOFF)cbAllocMem == cbAllocFile) 64 else 65 rc = VERR_OUT_OF_RANGE; 66 if (RT_SUCCESS(rc)) 63 67 { 64 /* 65 * Try allocate the required memory and initialize the header (hardcoded fun). 66 */ 67 void *pvHdr = RTMemAlloc(cbAllocMem + 32 + (fFlags & RTFILE_RDALL_F_TRAILING_ZERO_BYTE ? 1 : 0)); 68 if (pvHdr) 68 size_t cbAllocMem = (size_t)cbAllocFile; 69 if ((RTFOFF)cbAllocMem == cbAllocFile) 69 70 { 70 memset(pvHdr, 0xff, 32); 71 *(size_t *)pvHdr = cbAllocMem; 71 /* 72 * Try allocate the required memory and initialize the header (hardcoded fun). 73 */ 74 void *pvHdr = RTMemAlloc(cbAllocMem + 32 + (fFlags & RTFILE_RDALL_F_TRAILING_ZERO_BYTE ? 1 : 0)); 75 if (pvHdr) 76 { 77 memset(pvHdr, 0xff, 32); 78 *(size_t *)pvHdr = cbAllocMem; 72 79 73 /* 74 * Seek and read. 75 */ 76 rc = RTFileSeek(File, off, RTFILE_SEEK_BEGIN, NULL); 77 if (RT_SUCCESS(rc)) 78 { 79 void *pvFile = (uint8_t *)pvHdr + 32; 80 rc = RTFileRead(File, pvFile, cbAllocMem, NULL); 80 /* 81 * Seek and read. 82 */ 83 rc = RTFileSeek(File, off, RTFILE_SEEK_BEGIN, NULL); 81 84 if (RT_SUCCESS(rc)) 82 85 { 83 if (fFlags & RTFILE_RDALL_F_TRAILING_ZERO_BYTE) 84 ((uint8_t *)pvFile)[cbAllocFile] = '\0'; 86 void *pvFile = (uint8_t *)pvHdr + 32; 87 rc = RTFileRead(File, pvFile, cbAllocMem, NULL); 88 if (RT_SUCCESS(rc)) 89 { 90 if (fFlags & RTFILE_RDALL_F_TRAILING_ZERO_BYTE) 91 ((uint8_t *)pvFile)[cbAllocFile] = '\0'; 85 92 86 /* 87 * Success - fill in the return values. 88 */ 89 *ppvFile = pvFile; 90 *pcbFile = cbAllocMem; 93 /* 94 * Success - fill in the return values. 95 */ 96 *ppvFile = pvFile; 97 *pcbFile = cbAllocMem; 98 } 91 99 } 100 101 if (RT_FAILURE(rc)) 102 RTMemFree(pvHdr); 92 103 } 93 94 if (RT_FAILURE(rc)) 95 RTMemFree(pvHdr); 104 else 105 rc = VERR_NO_MEMORY; 96 106 } 97 107 else 98 rc = VERR_ NO_MEMORY;108 rc = VERR_TOO_MUCH_DATA; 99 109 } 100 else101 rc = VERR_TOO_MUCH_DATA;102 110 } 103 111 /* restore the position. */
Note:
See TracChangeset
for help on using the changeset viewer.