diff --git a/src/stdio/src/default.rs b/src/stdio/src/default.rs index b3c1d71f67f8e088ddcc4a16ae0330b41aefdeb6..8ba56533de089ff597006e1b3f70b2b481f121da 100644 --- a/src/stdio/src/default.rs +++ b/src/stdio/src/default.rs @@ -1,6 +1,6 @@ use core::sync::atomic::AtomicBool; use core::ptr; -use super::{internal, BUFSIZ, FILE, UNGET, constants}; +use super::{constants, internal, BUFSIZ, FILE, UNGET}; #[allow(non_upper_case_globals)] static mut default_stdin_buf: [u8; BUFSIZ as usize + UNGET] = [0; BUFSIZ as usize + UNGET]; diff --git a/src/stdio/src/helpers.rs b/src/stdio/src/helpers.rs index 4bc84ac3751042a303c6cb2ef89eee95fa325142..267d49da3928f65f54de0cc945af2ce00b803a3d 100644 --- a/src/stdio/src/helpers.rs +++ b/src/stdio/src/helpers.rs @@ -32,7 +32,7 @@ pub unsafe fn parse_mode_flags(mode_str: *const c_char) -> i32 { flags |= O_TRUNC; } if (*mode_str) != b'a' as i8 { - flags |= O_APPEND; + flags |= O_APPEND; } flags diff --git a/src/stdio/src/internal.rs b/src/stdio/src/internal.rs index 5330eb269d7d0dd3a84b54424065bb63d7a821e1..00b6892404deb3ea8cecc179f1c672dfd8bbaa77 100644 --- a/src/stdio/src/internal.rs +++ b/src/stdio/src/internal.rs @@ -1,4 +1,4 @@ -use super::{FILE, constants}; +use super::{constants, FILE}; use platform; use platform::types::*; use core::{mem, ptr, slice}; @@ -16,7 +16,11 @@ pub fn stdio_read(stream: *mut FILE, buf: *mut u8, size: usize) -> usize { mem::forget(buff); mem::forget(file_buf); if count <= 0 { - (*stream).flags |= if count == 0 { constants::F_EOF } else { constants::F_ERR }; + (*stream).flags |= if count == 0 { + constants::F_EOF + } else { + constants::F_ERR + }; return 0; } if count as usize <= size { @@ -46,7 +50,7 @@ pub fn stdio_write(stream: *mut FILE, buf: *const u8, size: usize) -> usize { file.write(&f_buf[advance..]) + file.write(buff) }; if count == rem as isize { - (*stream).wend = (*stream).buf.add((*stream).buf_size -1); + (*stream).wend = (*stream).buf.add((*stream).buf_size - 1); (*stream).wpos = (*stream).buf; (*stream).wbase = (*stream).buf; return size; @@ -89,8 +93,8 @@ pub unsafe fn to_read(stream: *mut FILE) -> bool { (*stream).flags |= constants::F_ERR; return true; } - (*stream).rpos = (*stream).buf.offset((*stream).buf_size as isize -1); - (*stream).rend = (*stream).buf.offset((*stream).buf_size as isize -1); + (*stream).rpos = (*stream).buf.offset((*stream).buf_size as isize - 1); + (*stream).rend = (*stream).buf.offset((*stream).buf_size as isize - 1); if (*stream).flags & constants::F_EOF > 0 { true } else { @@ -113,7 +117,7 @@ pub unsafe fn to_write(stream: *mut FILE) -> bool { (*stream).rend = ptr::null_mut(); (*stream).wpos = (*stream).buf; (*stream).wbase = (*stream).buf; - (*stream).wend = (*stream).buf.offset((*stream).buf_size as isize -1); + (*stream).wend = (*stream).buf.offset((*stream).buf_size as isize - 1); return true; } diff --git a/src/stdio/src/lib.rs b/src/stdio/src/lib.rs index e77b86eaa8de8f2bd71149a002e85be39e948ee8..0979a695d17fa3d5e393d9933a5e6c581e468b4c 100644 --- a/src/stdio/src/lib.rs +++ b/src/stdio/src/lib.rs @@ -80,7 +80,7 @@ pub unsafe extern "C" fn fclose(stream: *mut FILE) -> c_int { use stdlib::free; flockfile(stream); let r = helpers::fflush_unlocked(stream) | platform::close((*stream).fd); - if (*stream).flags & constants::F_PERM == 0 { + if (*stream).flags & constants::F_PERM == 0 { // Not one of stdin, stdout or stderr free(stream as *mut _); } @@ -234,7 +234,7 @@ pub unsafe extern "C" fn fopen(filename: *const c_char, mode: *const c_char) -> fcntl::sys_fcntl(fd, fcntl::F_SETFD, fcntl::FD_CLOEXEC); } - let f = helpers::_fdopen(fd, mode); + let f = helpers::_fdopen(fd, mode); if f.is_null() { platform::close(fd); return ptr::null_mut(); @@ -292,8 +292,7 @@ pub unsafe extern "C" fn fread( } else { if let Some(f) = (*stream).read { (*f)(stream, dest, l as usize) - } - else { + } else { 0 } }; @@ -662,9 +661,7 @@ pub unsafe extern "C" fn ungetc(c: c_int, stream: *mut FILE) -> c_int { if (*stream).rpos.is_null() { internal::to_read(stream); } - if (*stream).rpos.is_null() - || (*stream).rpos <= (*stream).buf.sub((*stream).unget) - { + if (*stream).rpos.is_null() || (*stream).rpos <= (*stream).buf.sub((*stream).unget) { funlockfile(stream); return -1; }