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(...@@ -1737,7 +1737,8 @@ pub fn writer_writeFile(
1737 const smaller_len = if (len_int == 0) max_count else @min(len_int, max_count);1737 const smaller_len = if (len_int == 0) max_count else @min(len_int, max_count);
1738 var off: std.os.linux.off_t = undefined;1738 var off: std.os.linux.off_t = undefined;
1739 const off_ptr: ?*std.os.linux.off_t = if (in_offset.toInt()) |offset| b: {1739 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);
1741 break :b &off;1742 break :b &off;
1742 } else null;1743 } else null;
1743 if (true) @panic("TODO");1744 if (true) @panic("TODO");
...@@ -1747,7 +1748,13 @@ pub fn writer_writeFile(...@@ -1747,7 +1748,13 @@ pub fn writer_writeFile(
1747 error.Unexpected => break :sf,1748 error.Unexpected => break :sf,
1748 else => |e| return e,1749 else => |e| return e,
1749 };1750 };
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 }
1751 return n;1758 return n;
1752 }1759 }
1753 var iovecs_buffer: [max_buffers_len]std.posix.iovec_const = undefined;1760 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 {...@@ -69,7 +69,8 @@ pub fn reset(bw: *BufferedWriter) void {
69pub fn flush(bw: *BufferedWriter) anyerror!void {69pub fn flush(bw: *BufferedWriter) anyerror!void {
70 const list = &bw.buffer;70 const list = &bw.buffer;
71 const send_buffer = list.items;71 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..]});
73 list.items.len = 0;74 list.items.len = 0;
74}75}
7576
lib/std/io/Writer.zig+3
...@@ -149,6 +149,9 @@ fn null_writeFile(...@@ -149,6 +149,9 @@ fn null_writeFile(
149) anyerror!usize {149) anyerror!usize {
150 _ = context;150 _ = context;
151 var n: usize = 0;151 var n: usize = 0;
152 if (offset == .none) {
153 @panic("TODO seek the file forwards");
154 }
152 if (len == .entire_file) {155 if (len == .entire_file) {
153 const headers = headers_and_trailers[0..headers_len];156 const headers = headers_and_trailers[0..headers_len];
154 for (headers) |bytes| n += bytes.len;157 for (headers) |bytes| n += bytes.len;
lib/std/posix.zig+3-4
...@@ -6359,7 +6359,7 @@ pub const SendFileError = PReadError || WriteError || SendError;...@@ -6359,7 +6359,7 @@ pub const SendFileError = PReadError || WriteError || SendError;
6359pub fn sendfile(6359pub fn sendfile(
6360 out_fd: fd_t,6360 out_fd: fd_t,
6361 in_fd: fd_t,6361 in_fd: fd_t,
6362 in_offset: ?u64,6362 in_offset: u64,
6363 in_len: u64,6363 in_len: u64,
6364 headers: []const iovec_const,6364 headers: []const iovec_const,
6365 trailers: []const iovec_const,6365 trailers: []const iovec_const,
...@@ -6390,9 +6390,8 @@ pub fn sendfile(...@@ -6390,9 +6390,8 @@ pub fn sendfile(
63906390
6391 const sendfile_sym = if (lfs64_abi) system.sendfile64 else system.sendfile;6391 const sendfile_sym = if (lfs64_abi) system.sendfile64 else system.sendfile;
6392 while (true) {6392 while (true) {
6393 var offset: off_t = if (in_offset) |o| o else undefined;6393 var offset: off_t = @bitCast(in_offset);
6394 const offset_pointer: ?*off_t = if (in_offset) &offset else null;6394 const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count);
6395 const rc = sendfile_sym(out_fd, in_fd, offset_pointer, adjusted_count);
6396 switch (errno(rc)) {6395 switch (errno(rc)) {
6397 .SUCCESS => {6396 .SUCCESS => {
6398 const amt: usize = @bitCast(rc);6397 const amt: usize = @bitCast(rc);
test/standalone/simple/hello_world/hello.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn main() !void {3pub fn main() !void {
4 try std.io.getStdOut().writeAll("Hello, World!\n");4 try std.fs.File.stdout().writeAll("Hello, World!\n");
5}5}