const std = @import("std");
const c = @cImport({ @cInclude("unistd.h"); });
const module = @import("../module.zig");

fn cb() ![]const u8 {
    var file = try std.fs.openFileAbsolute("/etc/hostname", .{});
    defer file.close();

    const max_hostname_size = c.sysconf(c._SC_HOST_NAME_MAX);
    const buffer = try std.heap.page_allocator.alloc(u8, @intCast(max_hostname_size));
    const bytes_read = try file.read(buffer);
    return buffer[0..bytes_read];
}

pub const hostname = module {
    .name = "hostname",
    .prefix = "Hostname: ",
    .callback = cb
};
