aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2022-10-29 05:58:41 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2022-10-29 05:58:41 -0400
commit48a2783969b0a43200514a5b4e9cce57be4e5b46 (patch)
tree0f7cc577dd9090938d842250e1d1986d3d05aa0e /lib/std/os.zig
parente20d2b3151607fe078b43331ea27d5b34f95360b (diff)
parent20925b2f5c5c0ae20fdc0574e5d4e5740d17b4d6 (diff)
downloadzig-48a2783969b0a43200514a5b4e9cce57be4e5b46.tar.gz
zig-48a2783969b0a43200514a5b4e9cce57be4e5b46.zip
cbe: implement optional slice representation change
Diffstat (limited to 'lib/std/os.zig')
-rw-r--r--lib/std/os.zig50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig
index 74ffd4de12..e69a2a7943 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -366,6 +366,56 @@ pub fn fchown(fd: fd_t, owner: ?uid_t, group: ?gid_t) FChownError!void {
}
}
+pub const RebootError = error{
+ PermissionDenied,
+} || UnexpectedError;
+
+pub const RebootCommand = switch (builtin.os.tag) {
+ .linux => union(linux.LINUX_REBOOT.CMD) {
+ RESTART: void,
+ HALT: void,
+ CAD_ON: void,
+ CAD_OFF: void,
+ POWER_OFF: void,
+ RESTART2: [*:0]const u8,
+ SW_SUSPEND: void,
+ KEXEC: void,
+ },
+ else => @compileError("Unsupported OS"),
+};
+
+pub fn reboot(cmd: RebootCommand) RebootError!void {
+ switch (builtin.os.tag) {
+ .linux => {
+ switch (system.getErrno(linux.reboot(
+ .MAGIC1,
+ .MAGIC2,
+ @as(linux.LINUX_REBOOT.CMD, cmd),
+ switch (cmd) {
+ .RESTART2 => |s| s,
+ else => null,
+ },
+ ))) {
+ .SUCCESS => {},
+ .PERM => return error.PermissionDenied,
+ else => |err| return std.os.unexpectedErrno(err),
+ }
+ switch (cmd) {
+ .CAD_OFF => {},
+ .CAD_ON => {},
+ .SW_SUSPEND => {},
+
+ .HALT => unreachable,
+ .KEXEC => unreachable,
+ .POWER_OFF => unreachable,
+ .RESTART => unreachable,
+ .RESTART2 => unreachable,
+ }
+ },
+ else => @compileError("Unsupported OS"),
+ }
+}
+
pub const GetRandomError = OpenError;
/// Obtain a series of random bytes. These bytes can be used to seed user-space