diff --git a/src/crti/src/lib.rs b/src/crti/src/lib.rs index 8071f059005a1f7837594b2e8c4a9f16e5cd02c5..77e8f055da8982c9f9b17aa256c36c3b35d066e0 100644 --- a/src/crti/src/lib.rs +++ b/src/crti/src/lib.rs @@ -27,7 +27,8 @@ global_asm!( ); // https://git.musl-libc.org/cgit/musl/tree/crt/aarch64/crti.s #[cfg(target_arch = "aarch64")] -global_asm!(r#" +global_asm!( + r#" .section .init .global _init .type _init,%function @@ -45,7 +46,8 @@ global_asm!(r#" mov x29,sp // stp: "stores two doublewords from the first and second argument to memory addressed by addr" // Body will be filled in by gcc and ended by crtn.o -"#); +"# +); #[panic_handler] #[linkage = "weak"] diff --git a/src/crtn/src/lib.rs b/src/crtn/src/lib.rs index 6704d357e978c3e08a71b5a12bdc99ffd907c0e1..b2d96086786997d93361ac38cb98aa755a8a5cd7 100644 --- a/src/crtn/src/lib.rs +++ b/src/crtn/src/lib.rs @@ -23,7 +23,8 @@ global_asm!( ); // https://git.musl-libc.org/cgit/musl/tree/crt/aarch64/crtn.s #[cfg(target_arch = "aarch64")] -global_asm!(r#" +global_asm!( + r#" .section .init // This happens after crti.o and gcc has inserted code // ldp: "loads two doublewords from memory addressed by the third argument to the first and second" @@ -35,7 +36,8 @@ global_asm!(r#" // ldp: "loads two doublewords from memory addressed by the third argument to the first and second" ldp x29,x30,[sp],#16 ret -"#); +"# +); #[panic_handler] #[linkage = "weak"] diff --git a/src/header/stdio/lookaheadreader.rs b/src/header/stdio/lookaheadreader.rs index 5c08d8675171eba46cdb7d4239cfbf3c177df386..91092f5af531c3824fe156938b67a804103e0ed8 100644 --- a/src/header/stdio/lookaheadreader.rs +++ b/src/header/stdio/lookaheadreader.rs @@ -1,4 +1,4 @@ -use super::{fseek_locked, FILE, SEEK_SET, ftell_locked}; +use super::{fseek_locked, ftell_locked, FILE, SEEK_SET}; use crate::core_io::Read; struct LookAheadBuffer { buf: *const u8, @@ -27,23 +27,22 @@ impl From<*const u8> for LookAheadBuffer { } } - struct LookAheadFile<'a> { f: &'a mut FILE, look_ahead: i64, } -impl <'a> LookAheadFile<'a> { +impl<'a> LookAheadFile<'a> { fn look_ahead(&mut self) -> Result<Option<u8>, i32> { let buf = &mut [0]; - let seek = unsafe{ ftell_locked(self.f)}; - unsafe{fseek_locked(self.f, self.look_ahead, SEEK_SET)}; + let seek = unsafe { ftell_locked(self.f) }; + unsafe { fseek_locked(self.f, self.look_ahead, SEEK_SET) }; let ret = match self.f.read(buf) { Ok(0) => Ok(None), Ok(_) => Ok(Some(buf[0])), Err(_) => Err(-1), }; - unsafe{fseek_locked(self.f, seek, SEEK_SET)}; + unsafe { fseek_locked(self.f, seek, SEEK_SET) }; self.look_ahead += 1; ret } @@ -53,17 +52,13 @@ impl <'a> LookAheadFile<'a> { } } -impl <'a> From<&'a mut FILE> for LookAheadFile<'a> { +impl<'a> From<&'a mut FILE> for LookAheadFile<'a> { fn from(f: &'a mut FILE) -> LookAheadFile<'a> { - let look_ahead = unsafe{ftell_locked(f)} as i64; - LookAheadFile{ - f, - look_ahead, - } + let look_ahead = unsafe { ftell_locked(f) } as i64; + LookAheadFile { f, look_ahead } } } - enum LookAheadReaderEnum<'a> { FILE(LookAheadFile<'a>), // (buffer, location) @@ -72,7 +67,7 @@ enum LookAheadReaderEnum<'a> { pub struct LookAheadReader<'a>(LookAheadReaderEnum<'a>); -impl <'a> LookAheadReader<'a> { +impl<'a> LookAheadReader<'a> { pub fn lookahead1(&mut self) -> Result<Option<u8>, i32> { match &mut self.0 { LookAheadReaderEnum::FILE(f) => f.look_ahead(), @@ -87,13 +82,13 @@ impl <'a> LookAheadReader<'a> { } } -impl <'a> From<&'a mut FILE> for LookAheadReader<'a> { +impl<'a> From<&'a mut FILE> for LookAheadReader<'a> { fn from(f: &'a mut FILE) -> LookAheadReader { LookAheadReader(LookAheadReaderEnum::FILE(f.into())) } } -impl <'a> From<*const u8> for LookAheadReader<'a > { +impl<'a> From<*const u8> for LookAheadReader<'a> { fn from(buff: *const u8) -> LookAheadReader<'a> { LookAheadReader(LookAheadReaderEnum::BUFFER(buff.into())) } diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index 2ec1ef15f7192e9adc8c3e0e4593346c40ad168f..2b22cf4ac57a29698309c9e228cb202b028046ba 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -516,7 +516,6 @@ pub unsafe extern "C" fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) /// Seek to an offset `offset` from `whence` #[no_mangle] pub unsafe extern "C" fn fseeko(stream: *mut FILE, off: off_t, whence: c_int) -> c_int { - let mut stream = (*stream).lock(); fseek_locked(&mut *stream, off, whence) } @@ -1051,7 +1050,7 @@ pub unsafe extern "C" fn vsprintf(s: *mut c_char, format: *const c_char, ap: va_ pub unsafe extern "C" fn vfscanf(file: *mut FILE, format: *const c_char, ap: va_list) -> c_int { let ret = { let mut file = (*file).lock(); - let f :&mut FILE = &mut *file; + let f: &mut FILE = &mut *file; let reader: LookAheadReader = f.into(); scanf::scanf(reader, format, ap) }; diff --git a/src/header/sys_random/mod.rs b/src/header/sys_random/mod.rs index 7543ca995d7fdea8b1fa3d49403e2897109342b2..957f8c7753eb374471cf095f37b8956799180716 100644 --- a/src/header/sys_random/mod.rs +++ b/src/header/sys_random/mod.rs @@ -1,14 +1,14 @@ use core::slice; -use crate::platform::{Pal, Sys, types::*}; +use crate::platform::{types::*, Pal, Sys}; pub const GRND_NONBLOCK: c_uint = 1; pub const GRND_RANDOM: c_uint = 2; #[no_mangle] pub unsafe extern "C" fn getrandom(buf: *mut c_void, buflen: size_t, flags: c_uint) -> ssize_t { - Sys::getrandom(slice::from_raw_parts_mut( - buf as *mut u8, - buflen as usize - ), flags) + Sys::getrandom( + slice::from_raw_parts_mut(buf as *mut u8, buflen as usize), + flags, + ) } diff --git a/src/platform/redox/ptrace.rs b/src/platform/redox/ptrace.rs index b5fd2d16e6fcb10254eb6fe9a030bbbb106c7797..665f5dcd002580614ddae309ca34d6848ae38958 100644 --- a/src/platform/redox/ptrace.rs +++ b/src/platform/redox/ptrace.rs @@ -5,6 +5,10 @@ //! compatibility. So, this module will be a hellhole. use super::super::{errno, types::*, Pal, PalPtrace, PalSignal, Sys}; +#[cfg(target_arch = "aarch64")] +use crate::header::arch_aarch64_user::user_regs_struct; +#[cfg(target_arch = "x86_64")] +use crate::header::arch_x64_user::user_regs_struct; use crate::{ c_str::CString, fs::File, @@ -12,10 +16,6 @@ use crate::{ io::{self, prelude::*}, sync::{Mutex, Once}, }; -#[cfg(target_arch = "aarch64")] -use crate::header::arch_aarch64_user::user_regs_struct; -#[cfg(target_arch = "x86_64")] -use crate::header::arch_x64_user::user_regs_struct; use alloc::collections::{btree_map::Entry, BTreeMap}; use core::mem; diff --git a/src/platform/redox/socket.rs b/src/platform/redox/socket.rs index 5937bdfb3d5267c6633e33514b2a7c4137c8ccf1..01d6e851933d483faafb8aee3c3c00172f44f42c 100644 --- a/src/platform/redox/socket.rs +++ b/src/platform/redox/socket.rs @@ -143,7 +143,10 @@ unsafe fn inner_get_name( inner_af_unix(&buf[5..], address, address_len); } else { // Socket doesn't belong to any scheme - panic!("socket {:?} doesn't match either tcp, udp or chan schemes", str::from_utf8(buf)); + panic!( + "socket {:?} doesn't match either tcp, udp or chan schemes", + str::from_utf8(buf) + ); } Ok(0) diff --git a/src/platform/test/mod.rs b/src/platform/test/mod.rs index d5fb9e04787f93610ab630ff982fdc5e1b48f188..721db1b9309dc50c270f853e68a505adc030da69 100644 --- a/src/platform/test/mod.rs +++ b/src/platform/test/mod.rs @@ -68,12 +68,14 @@ fn clock_gettime() { #[test] fn getrandom() { - use crate::header::sys_random; - use crate::platform::types::ssize_t; + use crate::{header::sys_random, platform::types::ssize_t}; let mut arrays = [[0; 32]; 32]; for i in 1..arrays.len() { - assert_eq!(Sys::getrandom(&mut arrays[i], 0), arrays[i].len() as ssize_t); + assert_eq!( + Sys::getrandom(&mut arrays[i], 0), + arrays[i].len() as ssize_t + ); for j in 0..arrays.len() { if i != j { diff --git a/tests/Makefile b/tests/Makefile index 7ff599552b593a5fe45f63d3b1eef0ab2253ca4b..594b17d6d422ec88370babeb16786e6652b4adc7 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -45,6 +45,7 @@ EXPECT_NAMES=\ stdio/ungetc_multiple \ stdio/ungetc_ftell \ stdio/fscanf_offby1 \ + stdio/fscanf \ stdio/printf_neg_pad \ stdlib/a64l \ stdlib/alloc \ diff --git a/tests/expected/stdio/fscanf.stderr b/tests/expected/stdio/fscanf.stderr new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/expected/stdio/fscanf.stdout b/tests/expected/stdio/fscanf.stdout new file mode 100644 index 0000000000000000000000000000000000000000..73f11e68cfb932d5c47fc7fd9a16f41ecd407dae --- /dev/null +++ b/tests/expected/stdio/fscanf.stdout @@ -0,0 +1,14 @@ +1 2 3 9 +9 +16 +35 +48 +92 +109 +152 +201 +241 +276 +293 +299 +301 diff --git a/tests/stdio/fscanf.c b/tests/stdio/fscanf.c new file mode 100644 index 0000000000000000000000000000000000000000..01d4c9c03b47298b64b39c648160ddd760f2be50 --- /dev/null +++ b/tests/stdio/fscanf.c @@ -0,0 +1,13 @@ +//@ 1 2 3 +//@ SS +#include <stdio.h> +int main() { + FILE *f = fopen("stdio/fscanf.c", "r"); + int x, y, z; + fscanf(f, "//@ %d %d %d",&x , &y, &z); + printf("%d %d %d %ld\n", x, y, z, ftell(f)); + while(-1 != fscanf(f, "%*[^\n]")) { + printf("%ld\n", ftell(f)); + getc(f); + } +} \ No newline at end of file