aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-02-28 03:11:37 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-02-28 14:51:56 -0500
commit07f52119de2a8bdb84389c73332e113cf12ac997 (patch)
tree807c9e2724d46f23fda91d25db212601df8ee5cc /lib/std/os.zig
parentef24f2dd93729493531c427aaac54444597f6e66 (diff)
downloadzig-07f52119de2a8bdb84389c73332e113cf12ac997.tar.gz
zig-07f52119de2a8bdb84389c73332e113cf12ac997.zip
implement native OS version detection for linux
Diffstat (limited to 'lib/std/os.zig')
-rw-r--r--lib/std/os.zig24
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig
index 9f349e7dc4..49e88bf9c7 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -3295,22 +3295,24 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
}
}
if (builtin.os.tag == .linux) {
- var uts: utsname = undefined;
- switch (errno(system.uname(&uts))) {
- 0 => {
- const hostname = mem.toSlice(u8, @ptrCast([*:0]u8, &uts.nodename));
- mem.copy(u8, name_buffer, hostname);
- return name_buffer[0..hostname.len];
- },
- EFAULT => unreachable,
- EPERM => return error.PermissionDenied,
- else => |err| return unexpectedErrno(err),
- }
+ const uts = uname();
+ const hostname = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &uts.nodename));
+ mem.copy(u8, name_buffer, hostname);
+ return name_buffer[0..hostname.len];
}
@compileError("TODO implement gethostname for this OS");
}
+pub fn uname() utsname {
+ var uts: utsname = undefined;
+ switch (errno(system.uname(&uts))) {
+ 0 => return uts,
+ EFAULT => unreachable,
+ else => unreachable,
+ }
+}
+
pub fn res_mkquery(
op: u4,
dname: []const u8,