blob: d5103196dec16b6f696bdc65cf8d63388ca87b11 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
use core::libc::c_int;
enum struct_termios {}
struct PreserveTermios {
priv state: *struct_termios,
}
fn PreserveTermios () -> ~PreserveTermios {
~PreserveTermios { state: unsafe { c::get() } }
}
impl Drop for PreserveTermios {
fn finalize (&self) {
unsafe { c::set(self.state) }
}
}
#[link_name = "termios_wrapper"]
extern mod c {
fn cooked () -> c_int;
fn cbreak () -> c_int;
fn raw () -> c_int;
fn echo (enable: c_int) -> c_int;
fn get() -> *struct_termios;
fn set(t: *struct_termios);
}
pub fn cooked () -> bool {
unsafe { c::cooked() as bool }
}
pub fn cbreak () -> bool {
unsafe { c::cbreak() as bool }
}
pub fn raw () -> bool {
unsafe { c::raw() as bool }
}
pub fn echo (enable: bool) -> bool {
unsafe { c::echo(enable as c_int) as bool }
}
pub fn preserve<T> (body: &fn () -> T) -> T {
let _guard = PreserveTermios();
body()
}
|