| ... | @@ -1048,12 +1048,27 @@ pub const File = struct { | ... | @@ -1048,12 +1048,27 @@ pub const File = struct { |
| 1048 | /// Returns the number of bytes read. If the number read is smaller than the total bytes | 1048 | /// Returns the number of bytes read. If the number read is smaller than the total bytes |
| 1049 | /// from all the buffers, it means the file reached the end. Reaching the end of a file | 1049 | /// from all the buffers, it means the file reached the end. Reaching the end of a file |
| 1050 | /// is not an error condition. | 1050 | /// is not an error condition. |
| 1051 | /// The `iovecs` parameter is mutable because this function needs to mutate the fields in | 1051 | /// |
| 1052 | /// order to handle partial reads from the underlying OS layer. | 1052 | /// The `iovecs` parameter is mutable because: |
| 1053 | /// See https://github.com/ziglang/zig/issues/7699 | 1053 | /// * This function needs to mutate the fields in order to handle partial |
| | 1054 | /// reads from the underlying OS layer. |
| | 1055 | /// * The OS layer expects pointer addresses to be inside the application's address space |
| | 1056 | /// even if the length is zero. Meanwhile, in Zig, slices may have undefined pointer |
| | 1057 | /// addresses when the length is zero. So this function modifies the iov_base fields |
| | 1058 | /// when the length is zero. |
| | 1059 | /// |
| | 1060 | /// Related open issue: https://github.com/ziglang/zig/issues/7699 |
| 1054 | pub fn readvAll(self: File, iovecs: []os.iovec) ReadError!usize { | 1061 | pub fn readvAll(self: File, iovecs: []os.iovec) ReadError!usize { |
| 1055 | if (iovecs.len == 0) return 0; | 1062 | if (iovecs.len == 0) return 0; |
| 1056 | | 1063 | |
| | 1064 | // We use the address of this local variable for all zero-length |
| | 1065 | // vectors so that the OS does not complain that we are giving it |
| | 1066 | // addresses outside the application's address space. |
| | 1067 | var garbage: [1]u8 = undefined; |
| | 1068 | for (iovecs) |*v| { |
| | 1069 | if (v.iov_len == 0) v.iov_base = &garbage; |
| | 1070 | } |
| | 1071 | |
| 1057 | var i: usize = 0; | 1072 | var i: usize = 0; |
| 1058 | var off: usize = 0; | 1073 | var off: usize = 0; |
| 1059 | while (true) { | 1074 | while (true) { |