| author | |
| committer | |
| log | e63daca92e959495be347525415ef1e520b01f44 |
| tree | afd49b1f9e2c9fdd2b4b39272a376cd57c9a28f2 |
| parent | 8a15537c6e32a756d4bdd54723504174c61c8c6a |
| signature |
4 files changed, 44 insertions(+), 0 deletions(-)
std/net.zig+8| ... | ... | @@ -245,3 +245,11 @@ pub fn connectUnixSocket(path: []const u8) !std.fs.File { |
| 245 | 245 | |
| 246 | 246 | return std.fs.File.openHandle(sockfd); |
| 247 | 247 | } |
| 248 | ||
| 249 | pub const getHostName = os.gethostname; | |
| 250 | ||
| 251 | test "getHostName" { | |
| 252 | var buf: [os.HOST_NAME_MAX]u8 = undefined; | |
| 253 | const hostname = try getHostName(&buf); | |
| 254 | expect(hostname.len != 0); | |
| 255 | } |
std/os.zig+22| ... | ... | @@ -2688,6 +2688,28 @@ pub fn futimens(fd: fd_t, times: *const [2]timespec) FutimensError!void { |
| 2688 | 2688 | } |
| 2689 | 2689 | } |
| 2690 | 2690 | |
| 2691 | pub const GetHostNameError = error{Unexpected}; | |
| 2692 | ||
| 2693 | pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { | |
| 2694 | if (builtin.link_libc) { | |
| 2695 | @compileError("TODO implement gethostname when linking libc"); | |
| 2696 | } | |
| 2697 | if (linux.is_the_target) { | |
| 2698 | var uts: utsname = undefined; | |
| 2699 | switch (errno(system.uname(&uts))) { | |
| 2700 | 0 => { | |
| 2701 | const hostname = mem.toSlice(u8, &uts.nodename); | |
| 2702 | mem.copy(u8, name_buffer, hostname); | |
| 2703 | return name_buffer[0..hostname.len]; | |
| 2704 | }, | |
| 2705 | EFAULT => unreachable, | |
| 2706 | else => |err| return unexpectedErrno(err), | |
| 2707 | } | |
| 2708 | } | |
| 2709 | ||
| 2710 | @compileError("TODO implement gethostname for this OS"); | |
| 2711 | } | |
| 2712 | ||
| 2691 | 2713 | test "" { |
| 2692 | 2714 | _ = @import("os/darwin.zig"); |
| 2693 | 2715 | _ = @import("os/freebsd.zig"); |
std/os/bits/linux.zig+10| ... | ... | @@ -1175,3 +1175,13 @@ pub const IORING_REGISTER_FILES = 2; |
| 1175 | 1175 | pub const IORING_UNREGISTER_FILES = 3; |
| 1176 | 1176 | pub const IORING_REGISTER_EVENTFD = 4; |
| 1177 | 1177 | pub const IORING_UNREGISTER_EVENTFD = 5; |
| 1178 | ||
| 1179 | pub const utsname = extern struct { | |
| 1180 | sysname: [65]u8, | |
| 1181 | nodename: [65]u8, | |
| 1182 | release: [65]u8, | |
| 1183 | version: [65]u8, | |
| 1184 | machine: [65]u8, | |
| 1185 | domainname: [65]u8, | |
| 1186 | }; | |
| 1187 | pub const HOST_NAME_MAX = 64; |
std/os/linux.zig+4| ... | ... | @@ -965,6 +965,10 @@ pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) usize { |
| 965 | 965 | return syscall2(SYS_sigaltstack, @ptrToInt(ss), @ptrToInt(old_ss)); |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | pub fn uname(uts: *utsname) usize { | |
| 969 | return syscall1(SYS_uname, @ptrToInt(uts)); | |
| 970 | } | |
| 971 | ||
| 968 | 972 | // XXX: This should be weak |
| 969 | 973 | extern const __ehdr_start: elf.Ehdr = undefined; |
| 970 | 974 |