Skip to content

Commit b19afe5

Browse files
committed
Use libc's declarations
1 parent bf796cc commit b19afe5

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/sys/reboot.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
11
use {Errno, Error, Result};
2-
use libc::c_int;
2+
use libc;
33
use void::Void;
44
use std::mem::drop;
55

6-
#[allow(overflowing_literals)]
6+
#[repr(i32)]
77
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
88
pub enum RebootMode {
9-
Halt = 0xcdef0123,
10-
kexec = 0x45584543,
11-
PowerOff = 0x4321fedc,
12-
Restart = 0x1234567,
9+
Halt = libc::RB_HALT_SYSTEM,
10+
kexec = libc::RB_KEXEC,
11+
PowerOff = libc::RB_POWER_OFF,
12+
Restart = libc::RB_AUTOBOOT,
1313
// we do not support Restart2,
14-
Suspend = 0xd000fce1,
14+
Suspend = libc::RB_SW_SUSPEND,
1515
}
1616

1717
pub fn reboot(how: RebootMode) -> Result<Void> {
1818
unsafe {
19-
ext::reboot(how as c_int)
19+
libc::reboot(how as libc::c_int)
2020
};
2121
Err(Error::Sys(Errno::last()))
2222
}
2323

24-
2524
/// Enable or disable the reboot keystroke (Ctrl-Alt-Delete).
2625
///
2726
/// Corresponds to calling `reboot(RB_ENABLE_CAD)` or `reboot(RB_DISABLE_CAD)` in C.
28-
#[allow(overflowing_literals)]
2927
pub fn set_cad_enabled(enable: bool) -> Result<()> {
28+
let cmd = if enable {
29+
libc::RB_ENABLE_CAD
30+
} else {
31+
libc::RB_DISABLE_CAD
32+
};
3033
let res = unsafe {
31-
ext::reboot(if enable { 0x89abcdef } else { 0 })
34+
libc::reboot(cmd)
3235
};
3336
Errno::result(res).map(drop)
3437
}
35-
36-
mod ext {
37-
use libc::c_int;
38-
extern {
39-
pub fn reboot(cmd: c_int) -> c_int;
40-
}
41-
}

0 commit comments

Comments
 (0)