diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-03-19 23:47:54 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-03-19 23:47:54 -0500 |
commit | b22139017fd30af86aea9badceac6eb44ac057aa (patch) | |
tree | 57e002d8602077d2189a38d241dab81942ce3e91 /src | |
parent | 7a0d31af21d363ca5fef535d69a37b4e11c5b1cb (diff) | |
download | rust-term-b22139017fd30af86aea9badceac6eb44ac057aa.tar.gz rust-term-b22139017fd30af86aea9badceac6eb44ac057aa.zip |
return errno on failure, not just false
Diffstat (limited to 'src')
-rw-r--r-- | src/ios.rs | 16 | ||||
-rw-r--r-- | src/termios_wrapper.c | 17 |
2 files changed, 17 insertions, 16 deletions
@@ -27,20 +27,20 @@ extern mod c { fn set(t: *struct_termios); } -pub fn cooked () -> bool { - unsafe { c::cooked() as bool } +pub fn cooked () -> int { + unsafe { c::cooked() as int } } -pub fn cbreak () -> bool { - unsafe { c::cbreak() as bool } +pub fn cbreak () -> int { + unsafe { c::cbreak() as int } } -pub fn raw () -> bool { - unsafe { c::raw() as bool } +pub fn raw () -> int { + unsafe { c::raw() as int } } -pub fn echo (enable: bool) -> bool { - unsafe { c::echo(enable as c_int) as bool } +pub fn echo (enable: bool) -> int { + unsafe { c::echo(enable as c_int) as int } } pub fn preserve<T> (body: &fn () -> T) -> T { diff --git a/src/termios_wrapper.c b/src/termios_wrapper.c index 77d589b..a245322 100644 --- a/src/termios_wrapper.c +++ b/src/termios_wrapper.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <errno.h> #include <termios.h> /* very simplistic, ignores a lot of the settings that i don't understand, @@ -9,13 +10,13 @@ int cooked() struct termios t; if (tcgetattr(0, &t) == -1) { - return 0; + return errno; } t.c_lflag |= (ICANON | ISIG | IEXTEN); t.c_iflag |= (IXON | BRKINT); - return tcsetattr(0, TCSANOW, &t) == 0; + return tcsetattr(0, TCSANOW, &t) == 0 ? 0 : errno; } int cbreak() @@ -23,14 +24,14 @@ int cbreak() struct termios t; if (tcgetattr(0, &t) == -1) { - return 0; + return errno; } t.c_lflag |= ISIG; t.c_lflag &= ~(ICANON | IEXTEN); t.c_iflag |= (IXON | BRKINT); - return tcsetattr(0, TCSANOW, &t) == 0; + return tcsetattr(0, TCSANOW, &t) == 0 ? 0 : errno; } int raw() @@ -38,13 +39,13 @@ int raw() struct termios t; if (tcgetattr(0, &t) == -1) { - return 0; + return errno; } t.c_lflag &= ~(ICANON | ISIG | IEXTEN); t.c_iflag &= ~(IXON | BRKINT); - return tcsetattr(0, TCSANOW, &t) == 0; + return tcsetattr(0, TCSANOW, &t) == 0 ? 0 : errno; } int echo(int enabled) @@ -52,7 +53,7 @@ int echo(int enabled) struct termios t; if (tcgetattr(0, &t) == -1) { - return 0; + return errno; } if (enabled) { @@ -62,7 +63,7 @@ int echo(int enabled) t.c_lflag &= ~ECHO; } - return tcsetattr(0, TCSANOW, &t) == 0; + return tcsetattr(0, TCSANOW, &t) == 0 ? 0 : errno; } struct termios *get() |