diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-06-22 23:22:17 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-06-22 23:22:17 -0400 |
| commit | 6938245fcc1daa6a63bcfcb3ba1092d569efc875 (patch) | |
| tree | 035b27a399c418cab679043f87282dc3de1ef5b1 /lib/std/fs.zig | |
| parent | 7b68385d7d4448e81cc882d9a5464bf58d10dc0d (diff) | |
| parent | 78c6d39cd49225bdfd2de4da7b1730ba26a41ba4 (diff) | |
| download | zig-6938245fcc1daa6a63bcfcb3ba1092d569efc875.tar.gz zig-6938245fcc1daa6a63bcfcb3ba1092d569efc875.zip | |
Merge remote-tracking branch 'origin/master' into zig-ast-to-zir
Diffstat (limited to 'lib/std/fs.zig')
| -rw-r--r-- | lib/std/fs.zig | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 262aa4872d..10422b9d54 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -261,17 +261,7 @@ pub const Dir = struct { name: []const u8, kind: Kind, - pub const Kind = enum { - BlockDevice, - CharacterDevice, - Directory, - NamedPipe, - SymLink, - File, - UnixDomainSocket, - Whiteout, - Unknown, - }; + pub const Kind = File.Kind; }; const IteratorError = error{AccessDenied} || os.UnexpectedError; @@ -1229,14 +1219,9 @@ pub const Dir = struct { var file = try self.openFile(file_path, .{}); defer file.close(); - const size = math.cast(usize, try file.getEndPos()) catch math.maxInt(usize); - if (size > max_bytes) return error.FileTooBig; - - const buf = try allocator.allocWithOptions(u8, size, alignment, optional_sentinel); - errdefer allocator.free(buf); + const stat_size = try file.getEndPos(); - try file.inStream().readNoEof(buf); - return buf; + return file.readAllAllocOptions(allocator, stat_size, max_bytes, alignment, optional_sentinel); } pub const DeleteTreeError = error{ @@ -1532,9 +1517,9 @@ pub const Dir = struct { var size: ?u64 = null; const mode = options.override_mode orelse blk: { - const stat = try in_file.stat(); - size = stat.size; - break :blk stat.mode; + const st = try in_file.stat(); + size = st.size; + break :blk st.mode; }; var atomic_file = try dest_dir.atomicFile(dest_path, .{ .mode = mode }); @@ -1560,6 +1545,17 @@ pub const Dir = struct { return AtomicFile.init(dest_path, options.mode, self, false); } } + + pub const Stat = File.Stat; + pub const StatError = File.StatError; + + pub fn stat(self: Dir) StatError!Stat { + const file: File = .{ + .handle = self.fd, + .capable_io_mode = .blocking, + }; + return file.stat(); + } }; /// Returns an handle to the current working directory. It is not opened with iteration capability. |
