chore: initial commit
This commit is contained in:
6
src/linux/linux.zig
Normal file
6
src/linux/linux.zig
Normal 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
6
src/macos/macos.zig
Normal 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
16
src/main.zig
Normal 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
8
src/root.zig
Normal 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
6
src/windows/windows.zig
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user