summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerin Stock <terinjokes@gmail.com>2020-01-11 21:00:20 -0800
committerTerin Stock <terinjokes@gmail.com>2020-01-11 21:00:20 -0800
commit9b4b14f0c0a869046dbb47804d46f9b3ab74a74d (patch)
treec607f643dad9507f4434839f69ba5c5ca1459bf8
parent87d8282897d31c39339ad4059a217fdde064983e (diff)
fix: remove FBA for headers
This changeset replaces the `allocPrint` and `FixedBufferAllocator` with `bufPrint`, which directly accepts the static buffer.
-rw-r--r--main.zig11
1 files changed, 6 insertions, 5 deletions
diff --git a/main.zig b/main.zig
index c1b78dd..650aa11 100644
--- a/main.zig
+++ b/main.zig
@@ -1,3 +1,5 @@
+// Copyright (c) 2020, Terin Stock
+//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
@@ -31,17 +33,16 @@ pub fn main() !void {
var pid = try os.fork();
switch (pid) {
0 => blk: {
- var mem: [512]u8 = undefined;
- const allocator = &heap.FixedBufferAllocator.init(mem[0..mem.len]).allocator;
+ var buf: [512]u8 = undefined;
+
var f = try fs.cwd().openFile("index.html", .{});
var stat = try f.stat();
- const hdr = std.fmt.allocPrint(
- allocator,
+ const hdr = std.fmt.bufPrint(
+ buf[0..buf.len],
"HTTP/1.1 200 OK\r\nServer: ziggetty\r\nConnection: closed\r\nContent-Length: {}\r\n\r\n",
.{stat.size},
) catch unreachable;
- errdefer allocator.free(hdr);
try conn.file.write(hdr);
// TODO: remove this cast