chore: initial commit

This commit is contained in:
utox39
2025-02-23 16:55:11 +01:00
commit 9e5f5ef3cf
8 changed files with 206 additions and 0 deletions

6
src/linux/linux.zig Normal file
View File

@@ -0,0 +1,6 @@
const std = @import("std");
pub fn getUsername(allocator: std.mem.Allocator) ![]u8 {
const username = try std.process.getEnvVarOwned(allocator, "USER");
return username;
}

6
src/macos/macos.zig Normal file
View File

@@ -0,0 +1,6 @@
const std = @import("std");
pub fn getUsername(allocator: std.mem.Allocator) ![]u8 {
const username = try std.process.getEnvVarOwned(allocator, "USER");
return username;
}

16
src/main.zig Normal file
View File

@@ -0,0 +1,16 @@
const std = @import("std");
const os_module = @import("root.zig").os_module;
pub fn main() !void {
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const username = try os_module.getUsername(allocator);
try stdout.print("User: {s}\n", .{username});
try bw.flush();
}

8
src/root.zig Normal file
View File

@@ -0,0 +1,8 @@
const std = @import("std");
pub const os_module = switch (@import("builtin").os.tag) {
.linux => @import("linux/linux.zig"),
.macos => @import("macos/macos.zig"),
.windows => @import("windows/windows.zig"),
else => @compileError("Unsupported operating system"),
};

6
src/windows/windows.zig Normal file
View File

@@ -0,0 +1,6 @@
const std = @import("std");
pub fn getUsername(allocator: std.mem.Allocator) ![]u8 {
const username = try std.process.getEnvVarOwned(allocator, "USERNAME");
return username;
}