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);
var off: std.os.linux.off_t = undefined;
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;
} else null;
if (true) @panic("TODO");
@ -1747,7 +1748,13 @@ pub fn writer_writeFile(
error.Unexpected => break :sf,
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;
}
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 {
const list = &bw.buffer;
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;
}

View File

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

View File

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

View File

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