aboutsummaryrefslogtreecommitdiff
path: root/lib/std/fs
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-05-12 01:02:48 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-05-12 01:02:48 -0400
commit619159cf48e953ca65933391313a72c392007710 (patch)
tree315cb12cff807374cd8fbbad3c06107241633565 /lib/std/fs
parenta32d3a85d21d614e5960b9eadcd85374954b910f (diff)
downloadzig-619159cf48e953ca65933391313a72c392007710.tar.gz
zig-619159cf48e953ca65933391313a72c392007710.zip
self-hosted: rework the memory layout of ir.Module and related types
* add TypedValue.Managed which represents a Type, a Value, and some kind of memory management strategy. * introduce an analysis queue * flesh out how incremental compilation works with respect to exports * ir.text.Module is only capable of one error message during parsing * link.zig no longer has a decl table map and instead has structs that exist directly on ir.Module.Decl and ir.Module.Export * implement primitive .text block allocation * implement linker code for updating Decls and Exports * implement null Type Some supporting std lib changes: * add std.ArrayList.appendSliceAssumeCapacity * add std.fs.File.copyRange and copyRangeAll * fix std.HashMap having modification safety on in ReleaseSmall builds * add std.HashMap.putAssumeCapacityNoClobber
Diffstat (limited to 'lib/std/fs')
-rw-r--r--lib/std/fs/file.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig
index b7c575a04a..a33d0d8e3e 100644
--- a/lib/std/fs/file.zig
+++ b/lib/std/fs/file.zig
@@ -527,6 +527,30 @@ pub const File = struct {
}
}
+ pub fn copyRange(in: File, in_offset: u64, out: File, out_offset: u64, len: usize) PWriteError!usize {
+ // TODO take advantage of copy_file_range OS APIs
+ var buf: [8 * 4096]u8 = undefined;
+ const adjusted_count = math.min(buf.len, len);
+ const amt_read = try in.pread(buf[0..adjusted_count], in_offset);
+ if (amt_read == 0) return 0;
+ return out.pwrite(buf[0..amt_read], out_offset);
+ }
+
+ /// 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: usize) PWriteError!usize {
+ var total_bytes_copied = 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 - total_bytes_copied);
+ if (amt_copied == 0) return total_bytes_copied;
+ total_bytes_copied += amt_copied;
+ in_off += amt_copied;
+ out_off += amt_copied;
+ }
+ }
+
pub const WriteFileOptions = struct {
in_offset: u64 = 0,