authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-04-09 22:46:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 16:35:26-07:00
logfaab6d5cbf18d25628793994e080f79d95adf4ea
treebb83b6a060c5a3113c671915411a257ebfa6ae44
parent1501734747afb60c6b28adb0da1e49ff46a31f17

fix hello world


5 files changed, 18 insertions(+), 8 deletions(-)

lib/std/fs/File.zig+9-2
......@@ -1737,7 +1737,8 @@ pub fn writer_writeFile(
17371737 const smaller_len = if (len_int == 0) max_count else @min(len_int, max_count);
17381738 var off: std.os.linux.off_t = undefined;
17391739 const off_ptr: ?*std.os.linux.off_t = if (in_offset.toInt()) |offset| b: {
1740 off = std.math.cast(std.os.linux.off_t, offset) orelse return error.Overflow;
1740 off = std.math.cast(std.os.linux.off_t, offset) orelse
1741 return writer_writeSplat(context, headers_and_trailers, 1);
17411742 break :b &off;
17421743 } else null;
17431744 if (true) @panic("TODO");
......@@ -1747,7 +1748,13 @@ pub fn writer_writeFile(
17471748 error.Unexpected => break :sf,
17481749 else => |e| return e,
17491750 };
1750 if (in_offset.toInt()) |offset| assert(n == off - offset);
1751 if (in_offset.toInt()) |offset| {
1752 assert(n == off - offset);
1753 } else if (n == 0 and len_int == 0) {
1754 // The caller wouldn't be able to tell that the file transfer is
1755 // done and would incorrectly repeat the same call.
1756 return writer_writeSplat(context, headers_and_trailers, 1);
1757 }
17511758 return n;
17521759 }
17531760 var iovecs_buffer: [max_buffers_len]std.posix.iovec_const = undefined;
lib/std/io/BufferedWriter.zig+2-1
......@@ -69,7 +69,8 @@ pub fn reset(bw: *BufferedWriter) void {
6969pub fn flush(bw: *BufferedWriter) anyerror!void {
7070 const list = &bw.buffer;
7171 const send_buffer = list.items;
72 try bw.unbuffered_writer.writeAll(send_buffer);
72 var index: usize = 0;
73 while (index < send_buffer.len) index += try bw.unbuffered_writer.writev(&.{send_buffer[index..]});
7374 list.items.len = 0;
7475}
7576
lib/std/io/Writer.zig+3
......@@ -149,6 +149,9 @@ fn null_writeFile(
149149) anyerror!usize {
150150 _ = context;
151151 var n: usize = 0;
152 if (offset == .none) {
153 @panic("TODO seek the file forwards");
154 }
152155 if (len == .entire_file) {
153156 const headers = headers_and_trailers[0..headers_len];
154157 for (headers) |bytes| n += bytes.len;
lib/std/posix.zig+3-4
......@@ -6359,7 +6359,7 @@ pub const SendFileError = PReadError || WriteError || SendError;
63596359pub fn sendfile(
63606360 out_fd: fd_t,
63616361 in_fd: fd_t,
6362 in_offset: ?u64,
6362 in_offset: u64,
63636363 in_len: u64,
63646364 headers: []const iovec_const,
63656365 trailers: []const iovec_const,
......@@ -6390,9 +6390,8 @@ pub fn sendfile(
63906390
63916391 const sendfile_sym = if (lfs64_abi) system.sendfile64 else system.sendfile;
63926392 while (true) {
6393 var offset: off_t = if (in_offset) |o| o else undefined;
6394 const offset_pointer: ?*off_t = if (in_offset) &offset else null;
6395 const rc = sendfile_sym(out_fd, in_fd, offset_pointer, adjusted_count);
6393 var offset: off_t = @bitCast(in_offset);
6394 const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count);
63966395 switch (errno(rc)) {
63976396 .SUCCESS => {
63986397 const amt: usize = @bitCast(rc);
test/standalone/simple/hello_world/hello.zig+1-1
......@@ -1,5 +1,5 @@
11const std = @import("std");
22
33pub fn main() !void {
4 try std.io.getStdOut().writeAll("Hello, World!\n");
4 try std.fs.File.stdout().writeAll("Hello, World!\n");
55}