瀏覽代碼

Fix some issues

Tom Almeida 6 年之前
父節點
當前提交
05b4b76426
共有 1 個文件被更改,包括 4 次插入41 次删除
  1. 4 41
      src/stdio/src/default.rs

+ 4 - 41
src/stdio/src/default.rs

@@ -1,44 +1,7 @@
 use core::sync::atomic::AtomicBool;
+use core::cell::UnsafeCell;
 use super::{constants, BUFSIZ, FILE, UNGET};
 
-lazy_static! {
-    #[allow(non_upper_case_globals)]
-    static ref default_stdin: FILE = FILE {
-        flags: constants::F_PERM | constants::F_NOWR | constants::F_BADJ,
-        read: None,
-        write: None,
-        fd: 0,
-        buf: vec![0u8;(BUFSIZ + UNGET) as usize],
-        buf_char: -1,
-        unget: UNGET,
-        lock: AtomicBool::new(false),
-    };
-
-    #[allow(non_upper_case_globals)]
-    static ref default_stdout: FILE = FILE {
-        flags: constants::F_PERM | constants::F_NORD | constants::F_BADJ,
-        read: None,
-        write: None,
-        fd: 1,
-        buf: vec![0u8;(BUFSIZ + UNGET) as usize],
-        buf_char: b'\n' as i8,
-        unget: 0,
-        lock: AtomicBool::new(false),
-    };
-
-    #[allow(non_upper_case_globals)]
-    static ref default_stderr: FILE = FILE {
-        flags: constants::F_PERM | constants::F_NORD | constants::F_BADJ,
-        read: None,
-        write: None,
-        fd: 2,
-        buf: vec![0u8;(BUFSIZ + UNGET) as usize],
-        buf_char: -1,
-        unget: 0,
-        lock: AtomicBool::new(false),
-    };
-}
-
 struct GlobalFile(UnsafeCell<FILE>);
 impl GlobalFile {
     const fn new(file: FILE) -> Self {
@@ -53,17 +16,17 @@ unsafe impl Sync for GlobalFile {}
 
 #[no_mangle]
 pub extern "C" fn __stdin() -> *mut FILE {
-    unsafe { &mut default_stdin }
+    unsafe { default_stdin.get() }
 }
 
 #[no_mangle]
 pub extern "C" fn __stdout() -> *mut FILE {
-    unsafe { &mut default_stdout }
+    unsafe { default_stdout.get() }
 }
 
 #[no_mangle]
 pub extern "C" fn __stderr() -> *mut FILE {
-    unsafe { &mut default_stderr }
+    unsafe { default_stderr.get() }
 }
 
 lazy_static! {