From 925d9f6bbfeb8c764d0ea32911bb1edbf2716953 Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jeremy@system76.com> Date: Sun, 2 Dec 2018 16:45:29 -0700 Subject: [PATCH] WIP: fflush all files when null is passed --- src/header/stdio/mod.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index e97aebdb..8ed46f14 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -251,8 +251,24 @@ pub unsafe extern "C" fn ferror(stream: *mut FILE) -> c_int { /// itself. #[no_mangle] pub unsafe extern "C" fn fflush(stream: *mut FILE) -> c_int { - let mut stream = (*stream).lock(); - stream.flush().is_err() as c_int + if stream.is_null() { + //TODO: flush all files! + + if fflush(stdout) != 0 { + return EOF; + } + + if fflush(stderr) != 0 { + return EOF; + } + } else { + let mut stream = (*stream).lock(); + if stream.flush().is_err() { + return EOF; + } + } + + 0 } /// Get a single char from a stream -- GitLab