From 7225bf186f469a24625c0a7e9cb31048ec351fd4 Mon Sep 17 00:00:00 2001 From: Abdelhakim Qbaich Date: Tue, 12 May 2020 01:35:20 -0400 Subject: [PATCH] Fixes --- lib/std/os/bits/freebsd.zig | 1 + lib/std/os/bits/netbsd.zig | 1 + lib/std/zig/system.zig | 7 ++++--- test/stage1/behavior/type_info.zig | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig index eee750436650..3ed1b4d2a676 100644 --- a/lib/std/os/bits/freebsd.zig +++ b/lib/std/os/bits/freebsd.zig @@ -213,6 +213,7 @@ pub const sockaddr_un = extern struct { pub const CTL_KERN = 1; pub const CTL_DEBUG = 5; +pub const KERN_OSRELEASE = 2; // string: system release pub const KERN_PROC = 14; // struct: process entries pub const KERN_PROC_PATHNAME = 12; // path to executable diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig index 680c6531d305..461e6359fba6 100644 --- a/lib/std/os/bits/netbsd.zig +++ b/lib/std/os/bits/netbsd.zig @@ -286,6 +286,7 @@ pub const AI_ADDRCONFIG = 0x00000400; pub const CTL_KERN = 1; pub const CTL_DEBUG = 5; +pub const KERN_OSRELEASE = 2; // string: system release pub const KERN_PROC_ARGS = 48; // struct: process argv/env pub const KERN_PROC_PATHNAME = 5; // path to executable diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 707a22487693..437e60cd81dd 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -300,10 +300,11 @@ pub const NativeTargetInfo = struct { @panic("unable to get the system release string"); }; - const release_version = if (mem.indexOfScalar(u8, buf, '-')) |pos| - buf[0 .. pos] + const release = mem.spanZ(buf); + const release_version = if (mem.indexOfScalar(u8, release, '-')) |pos| + release[0..pos] else - buf[0 .. len - 1]; + release; if (std.builtin.Version.parse(release_version)) |ver| { os.version_range.semver.min = ver; diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig index e910e29d4bf4..7de936e94d23 100644 --- a/test/stage1/behavior/type_info.zig +++ b/test/stage1/behavior/type_info.zig @@ -182,10 +182,10 @@ fn testEnum() void { const os_info = @typeInfo(Os); expect(os_info == .Enum); expect(os_info.Enum.layout == .Auto); - expect(os_info.Enum.fields.len == 4); + expect(os_info.Enum.fields.len == 5); expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos")); expect(os_info.Enum.fields[3].value == 3); - expect(os_info.Enum.tag_type == u2); + expect(os_info.Enum.tag_type == u3); expect(os_info.Enum.decls.len == 0); }