Slide 30
Slide 30 text
ࠔͬͨ͜ͱ 3/4
• Ұ෦ͷLinuxγεςϜίʔϧZigඪ४ϥΠϒϥϦͷ࣮͕ଘࡏ͠ͳ͍
• sethostname(2)ͳͲ
→ ฦΓͷerrnoΛ
ZigͷerrorʹϚοϓ͢Δ
࣮Λఆٛͯ͠ରԠ
pub fn valOrErr(val: anytype, errno: usize) LinuxKernelError!@TypeOf(val) {
return switch (os.errno(errno)) {
.SUCCESS => val,
.PERM => error.OperationNotPermitted,
// …
else => |e| return os.unexpectedErrno(e),
};
}
pub fn sethostname(hostname: []const u8) SetHostNameError!void {
const result = switch (native_arch) {
else => linux.syscall2(.sethostname, @ptrToInt(hostname.ptr),
hostname.len),
};
return valOrErr({}, result);
}