1const builtin = @import("builtin");
2
3const std = @import("std");
4
5const symbol = @import("../../c.zig").symbol;
6const errno = @import("../../c.zig").errno;
7
8comptime {
9 if (builtin.target.isMuslLibC()) {
10 symbol(&unameLinux, "uname");
11 }
12
13 if (builtin.target.isWasiLibC()) {
14 symbol(&unameWasi, "uname");
15 }
16}
17
18fn unameLinux(uts: *std.os.linux.utsname) callconv(.c) c_int {
19 return errno(std.os.linux.uname(uts));
20}
21
22fn unameWasi(uts: *std.c.utsname) callconv(.c) c_int {
23 // note the @bitCast's for NUL termination!
24 uts.sysname[0..5].* = @bitCast("wasi".*);
25 uts.nodename[0..7].* = @bitCast("(none)".*);
26 uts.release[0..6].* = @bitCast("0.0.0".*);
27 uts.version[0..6].* = @bitCast("0.0.0".*);
28 uts.machine[0..7].* = @bitCast(switch (builtin.target.cpu.arch) {
29 .wasm32 => "wasm32",
30 .wasm64 => "wasm64",
31 else => comptime unreachable,
32 }.*);
33 uts.domainname[0..7].* = @bitCast("(none)".*);
34 return 0;
35}