diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-10-07 00:39:13 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-10-07 00:39:13 -0700 |
| commit | b2b0bf0506e708e6b8c143eb438a84592310b5a9 (patch) | |
| tree | 28b7a8997249dafa8b1171e789fbb0dfce2a9d56 /lib/std/fs | |
| parent | bd7eab573a5e5f1366cd5dc3639fef28c4acb32a (diff) | |
| download | zig-b2b0bf0506e708e6b8c143eb438a84592310b5a9.tar.gz zig-b2b0bf0506e708e6b8c143eb438a84592310b5a9.zip | |
fixups for the previous commit
* std.fs.File.copyRange and copyRangeAll return u64 instead of usize -
the returned value is how much of the `len` is transferred, so the
types should match. This removes the need for an `@intCast`.
* fix typo that removed a subtraction
* Fix the size of codegen.AnyMCValue which gave me a compile error when
I tried to build self-hosted for i386-linux.
* restore the coercion to u64 of syms_sect.sh_info. We want to make
sure the multiplication happens with 64 bits and not the smaller type
used by the ELF format.
* fix another offset parameter in link/Elf.zig to be u64 instead of usize
* add a nice little TODO note to help out Jakub
* FmtError already has FileTooBig in it; we just need to return it.
Diffstat (limited to 'lib/std/fs')
| -rw-r--r-- | lib/std/fs/file.zig | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index e0795f4c1c..bfa6dec3ed 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -652,25 +652,26 @@ pub const File = struct { pub const CopyRangeError = os.CopyFileRangeError; - pub fn copyRange(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!usize { + pub fn copyRange(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64 { const adjusted_len = math.cast(usize, len) catch math.maxInt(usize); - return os.copy_file_range(in.handle, in_offset, out.handle, out_offset, adjusted_len, 0); + const result = try os.copy_file_range(in.handle, in_offset, out.handle, out_offset, adjusted_len, 0); + return result; } /// Returns the number of bytes copied. If the number read is smaller than `buffer.len`, it /// means the in file reached the end. Reaching the end of a file is not an error condition. - pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!usize { + pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64 { var total_bytes_copied: u64 = 0; var in_off = in_offset; var out_off = out_offset; while (total_bytes_copied < len) { - const amt_copied = try copyRange(in, in_off, out, out_off, len); - if (amt_copied == 0) return @intCast(usize, total_bytes_copied); + const amt_copied = try copyRange(in, in_off, out, out_off, len - total_bytes_copied); + if (amt_copied == 0) return total_bytes_copied; total_bytes_copied += amt_copied; in_off += amt_copied; out_off += amt_copied; } - return @intCast(usize, total_bytes_copied); + return total_bytes_copied; } pub const WriteFileOptions = struct { |
