authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-13 23:16:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:49-07:00
logc2d1a339da65da0c93fdd66df90955500417b3c9
tree9a8ebdfb9b3ba1f2f307063347e77457f3a6840a
parent79a59c516531650664511ac539ee6d7c6402169f

std.fs.File: begrudgingly add back deprecated APIs

I'm not ready to rework MachO linker file access at the moment.

1 files changed, 44 insertions(+), 0 deletions(-)

lib/std/fs/File.zig+44
...@@ -655,6 +655,17 @@ pub fn pread(self: File, buffer: []u8, offset: u64) PReadError!usize {...@@ -655,6 +655,17 @@ pub fn pread(self: File, buffer: []u8, offset: u64) PReadError!usize {
655 return posix.pread(self.handle, buffer, offset);655 return posix.pread(self.handle, buffer, offset);
656}656}
657657
658/// Deprecated in favor of `Reader`.
659pub fn preadAll(self: File, buffer: []u8, offset: u64) PReadError!usize {
660 var index: usize = 0;
661 while (index != buffer.len) {
662 const amt = try self.pread(buffer[index..], offset + index);
663 if (amt == 0) break;
664 index += amt;
665 }
666 return index;
667}
668
658/// See https://github.com/ziglang/zig/issues/7699669/// See https://github.com/ziglang/zig/issues/7699
659pub fn readv(self: File, iovecs: []const posix.iovec) ReadError!usize {670pub fn readv(self: File, iovecs: []const posix.iovec) ReadError!usize {
660 if (is_windows) {671 if (is_windows) {
...@@ -697,6 +708,14 @@ pub fn writeAll(self: File, bytes: []const u8) WriteError!void {...@@ -697,6 +708,14 @@ pub fn writeAll(self: File, bytes: []const u8) WriteError!void {
697 }708 }
698}709}
699710
711/// Deprecated in favor of `Writer`.
712pub fn pwriteAll(self: File, bytes: []const u8, offset: u64) PWriteError!void {
713 var index: usize = 0;
714 while (index < bytes.len) {
715 index += try self.pwrite(bytes[index..], offset + index);
716 }
717}
718
700/// On Windows, this function currently does alter the file pointer.719/// On Windows, this function currently does alter the file pointer.
701/// https://github.com/ziglang/zig/issues/12783720/// https://github.com/ziglang/zig/issues/12783
702pub fn pwrite(self: File, bytes: []const u8, offset: u64) PWriteError!usize {721pub fn pwrite(self: File, bytes: []const u8, offset: u64) PWriteError!usize {
...@@ -732,6 +751,31 @@ pub fn pwritev(self: File, iovecs: []posix.iovec_const, offset: u64) PWriteError...@@ -732,6 +751,31 @@ pub fn pwritev(self: File, iovecs: []posix.iovec_const, offset: u64) PWriteError
732 return posix.pwritev(self.handle, iovecs, offset);751 return posix.pwritev(self.handle, iovecs, offset);
733}752}
734753
754/// Deprecated in favor of `Writer`.
755pub const CopyRangeError = posix.CopyFileRangeError;
756
757/// Deprecated in favor of `Writer`.
758pub fn copyRange(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64 {
759 const adjusted_len = math.cast(usize, len) orelse maxInt(usize);
760 const result = try posix.copy_file_range(in.handle, in_offset, out.handle, out_offset, adjusted_len, 0);
761 return result;
762}
763
764/// Deprecated in favor of `Writer`.
765pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64 {
766 var total_bytes_copied: u64 = 0;
767 var in_off = in_offset;
768 var out_off = out_offset;
769 while (total_bytes_copied < len) {
770 const amt_copied = try copyRange(in, in_off, out, out_off, len - total_bytes_copied);
771 if (amt_copied == 0) return total_bytes_copied;
772 total_bytes_copied += amt_copied;
773 in_off += amt_copied;
774 out_off += amt_copied;
775 }
776 return total_bytes_copied;
777}
778
735/// Deprecated in favor of `Io.File.Reader`.779/// Deprecated in favor of `Io.File.Reader`.
736pub const Reader = Io.File.Reader;780pub const Reader = Io.File.Reader;
737781