slight change

This commit is contained in:
yf
2019-08-07 22:15:35 +08:00
parent e279364f13
commit 92ebc30c27

View File

@@ -868,11 +868,11 @@ pub fn os_ttyname(fd: PyIntRef, vm: &VirtualMachine) -> PyResult {
use libc::ttyname;
if let Some(fd) = fd.as_bigint().to_i32() {
let name = unsafe { ttyname(fd) };
if !name.is_null() {
if name.is_null() {
Err(vm.new_os_error(Error::last_os_error().to_string()))
} else {
let name = unsafe { CStr::from_ptr(name) }.to_str().unwrap();
Ok(vm.ctx.new_str(name.to_owned()))
} else {
Err(vm.new_os_error(Error::last_os_error().to_string()))
}
} else {
Err(vm.new_overflow_error("signed integer is greater than maximum".to_owned()))