#why doesn't this print

1 messages · Page 1 of 1 (latest)

lament ginkgo
#
const std = @import("std");
const file = @import("std").fs.File;
pub fn meminfo(allocator: std.mem.Allocator) ![]u8 {
    const meminfo_file = try std.fs.openFileAbsolute("/proc/meminfo", .{ .mode = .read_only });
    const meminfo_file_stat = try meminfo_file.stat();
    const meminfo_file_size = meminfo_file_stat.size;
    const buffer = try allocator.alloc(u8, meminfo_file_size);

    _ = try meminfo_file.read(buffer);
    return buffer;
}

test "random test" {
    const a = std.testing.allocator;
    const meminfo_contents = try meminfo(a);
    std.debug.print("{s}", .{meminfo_contents});
}
foggy storm
#

it prints, but there is nothing to print; /proc/meminfo will always report a size of 0

#

you want File.readToEndAlloc

lament ginkgo
#

that works but since i only want the first line freeing the allocated memory becomes a problem

#

oh i can just copy the first line to a different memory and free the first allocation after i get what i want