fix hello world

This commit is contained in:
Andrew Kelley 2025-04-09 22:46:06 -07:00
parent 1501734747
commit faab6d5cbf
5 changed files with 18 additions and 8 deletions

View File

@ -1737,7 +1737,8 @@ pub fn writer_writeFile(
const smaller_len = if (len_int == 0) max_count else @min(len_int, max_count); const smaller_len = if (len_int == 0) max_count else @min(len_int, max_count);
var off: std.os.linux.off_t = undefined; var off: std.os.linux.off_t = undefined;
const off_ptr: ?*std.os.linux.off_t = if (in_offset.toInt()) |offset| b: { const off_ptr: ?*std.os.linux.off_t = if (in_offset.toInt()) |offset| b: {
off = std.math.cast(std.os.linux.off_t, offset) orelse return error.Overflow; off = std.math.cast(std.os.linux.off_t, offset) orelse
return writer_writeSplat(context, headers_and_trailers, 1);
break :b &off; break :b &off;
} else null; } else null;
if (true) @panic("TODO"); if (true) @panic("TODO");
@ -1747,7 +1748,13 @@ pub fn writer_writeFile(
error.Unexpected => break :sf, error.Unexpected => break :sf,
else => |e| return e, else => |e| return e,
}; };
if (in_offset.toInt()) |offset| assert(n == off - offset); if (in_offset.toInt()) |offset| {
assert(n == off - offset);
} else if (n == 0 and len_int == 0) {
// The caller wouldn't be able to tell that the file transfer is
// done and would incorrectly repeat the same call.
return writer_writeSplat(context, headers_and_trailers, 1);
}
return n; return n;
} }
var iovecs_buffer: [max_buffers_len]std.posix.iovec_const = undefined; var iovecs_buffer: [max_buffers_len]std.posix.iovec_const = undefined;

View File

@ -69,7 +69,8 @@ pub fn reset(bw: *BufferedWriter) void {
pub fn flush(bw: *BufferedWriter) anyerror!void { pub fn flush(bw: *BufferedWriter) anyerror!void {
const list = &bw.buffer; const list = &bw.buffer;
const send_buffer = list.items; const send_buffer = list.items;
try bw.unbuffered_writer.writeAll(send_buffer); var index: usize = 0;
while (index < send_buffer.len) index += try bw.unbuffered_writer.writev(&.{send_buffer[index..]});
list.items.len = 0; list.items.len = 0;
} }

View File

@ -149,6 +149,9 @@ fn null_writeFile(
) anyerror!usize { ) anyerror!usize {
_ = context; _ = context;
var n: usize = 0; var n: usize = 0;
if (offset == .none) {
@panic("TODO seek the file forwards");
}
if (len == .entire_file) { if (len == .entire_file) {
const headers = headers_and_trailers[0..headers_len]; const headers = headers_and_trailers[0..headers_len];
for (headers) |bytes| n += bytes.len; for (headers) |bytes| n += bytes.len;

View File

@ -6359,7 +6359,7 @@ pub const SendFileError = PReadError || WriteError || SendError;
pub fn sendfile( pub fn sendfile(
out_fd: fd_t, out_fd: fd_t,
in_fd: fd_t, in_fd: fd_t,
in_offset: ?u64, in_offset: u64,
in_len: u64, in_len: u64,
headers: []const iovec_const, headers: []const iovec_const,
trailers: []const iovec_const, trailers: []const iovec_const,
@ -6390,9 +6390,8 @@ pub fn sendfile(
const sendfile_sym = if (lfs64_abi) system.sendfile64 else system.sendfile; const sendfile_sym = if (lfs64_abi) system.sendfile64 else system.sendfile;
while (true) { while (true) {
var offset: off_t = if (in_offset) |o| o else undefined; var offset: off_t = @bitCast(in_offset);
const offset_pointer: ?*off_t = if (in_offset) &offset else null; const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count);
const rc = sendfile_sym(out_fd, in_fd, offset_pointer, adjusted_count);
switch (errno(rc)) { switch (errno(rc)) {
.SUCCESS => { .SUCCESS => {
const amt: usize = @bitCast(rc); const amt: usize = @bitCast(rc);

View File

@ -1,5 +1,5 @@
const std = @import("std"); const std = @import("std");
pub fn main() !void { pub fn main() !void {
try std.io.getStdOut().writeAll("Hello, World!\n"); try std.fs.File.stdout().writeAll("Hello, World!\n");
} }