| author | |
| committer | |
| log | 07f52119de2a8bdb84389c73332e113cf12ac997 |
| tree | 807c9e2724d46f23fda91d25db212601df8ee5cc |
| parent | ef24f2dd93729493531c427aaac54444597f6e66 |
| signature | Commit is signed but in an unrecognized format. |
3 files changed, 30 insertions(+), 12 deletions(-)
lib/std/c.zig+1| ... | ... | @@ -125,6 +125,7 @@ pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*u |
| 125 | 125 | pub extern "c" fn tcgetattr(fd: fd_t, termios_p: *termios) c_int; |
| 126 | 126 | pub extern "c" fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) c_int; |
| 127 | 127 | pub extern "c" fn fcntl(fd: fd_t, cmd: c_int, ...) c_int; |
| 128 | pub extern "c" fn uname(buf: *utsname) c_int; | |
| 128 | 129 | |
| 129 | 130 | pub extern "c" fn gethostname(name: [*]u8, len: usize) c_int; |
| 130 | 131 | pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int; |
lib/std/os.zig+13-11| ... | ... | @@ -3295,22 +3295,24 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { |
| 3295 | 3295 | } |
| 3296 | 3296 | } |
| 3297 | 3297 | if (builtin.os.tag == .linux) { |
| 3298 | var uts: utsname = undefined; | |
| 3299 | switch (errno(system.uname(&uts))) { | |
| 3300 | 0 => { | |
| 3301 | const hostname = mem.toSlice(u8, @ptrCast([*:0]u8, &uts.nodename)); | |
| 3302 | mem.copy(u8, name_buffer, hostname); | |
| 3303 | return name_buffer[0..hostname.len]; | |
| 3304 | }, | |
| 3305 | EFAULT => unreachable, | |
| 3306 | EPERM => return error.PermissionDenied, | |
| 3307 | else => |err| return unexpectedErrno(err), | |
| 3308 | } | |
| 3298 | const uts = uname(); | |
| 3299 | const hostname = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &uts.nodename)); | |
| 3300 | mem.copy(u8, name_buffer, hostname); | |
| 3301 | return name_buffer[0..hostname.len]; | |
| 3309 | 3302 | } |
| 3310 | 3303 | |
| 3311 | 3304 | @compileError("TODO implement gethostname for this OS"); |
| 3312 | 3305 | } |
| 3313 | 3306 | |
| 3307 | pub fn uname() utsname { | |
| 3308 | var uts: utsname = undefined; | |
| 3309 | switch (errno(system.uname(&uts))) { | |
| 3310 | 0 => return uts, | |
| 3311 | EFAULT => unreachable, | |
| 3312 | else => unreachable, | |
| 3313 | } | |
| 3314 | } | |
| 3315 | ||
| 3314 | 3316 | pub fn res_mkquery( |
| 3315 | 3317 | op: u4, |
| 3316 | 3318 | dname: []const u8, |
lib/std/zig/system.zig+16-1| ... | ... | @@ -200,7 +200,22 @@ pub const NativeTargetInfo = struct { |
| 200 | 200 | const cpu = Target.Cpu.baseline(arch); |
| 201 | 201 | |
| 202 | 202 | // TODO Detect native operating system version. Until that is implemented we use the default range. |
| 203 | const os = Target.Os.defaultVersionRange(os_tag); | |
| 203 | var os = Target.Os.defaultVersionRange(os_tag); | |
| 204 | switch (Target.current.os.tag) { | |
| 205 | .linux => { | |
| 206 | const uts = std.os.uname(); | |
| 207 | const release = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &uts.release)); | |
| 208 | if (std.builtin.Version.parse(release)) |ver| { | |
| 209 | os.version_range.linux.range.min = ver; | |
| 210 | os.version_range.linux.range.max = ver; | |
| 211 | } else |err| switch (err) { | |
| 212 | error.Overflow => {}, | |
| 213 | error.InvalidCharacter => {}, | |
| 214 | error.InvalidVersion => {}, | |
| 215 | } | |
| 216 | }, | |
| 217 | else => {}, | |
| 218 | } | |
| 204 | 219 | |
| 205 | 220 | return detectAbiAndDynamicLinker(allocator, cpu, os); |
| 206 | 221 | } |