From 21d3f12572544de797b7d97d0743bc56365847d7 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 30 Sep 2023 23:55:56 +0200 Subject: [PATCH] fprintf --- rawc/src/stdio.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/rawc/src/stdio.rs b/rawc/src/stdio.rs index 4cd0128..6f0987e 100644 --- a/rawc/src/stdio.rs +++ b/rawc/src/stdio.rs @@ -28,6 +28,56 @@ pub unsafe extern "C" fn __printf_chk(_flag: c_int, format: *const u8, mut args: } } +#[no_mangle] +pub unsafe extern "C" fn printf(format: *const u8, mut args: ...) -> c_int { + let mut sink = WriteCounter(stdout, 0); + + let result = libuwuc::fmt::printf::printf_generic( + &mut sink, + SharedThinCstr::from_raw(format), + args.as_va_list(), + ); + + match result { + Ok(()) => sink.1 as _, + Err(err) => err, + } +} + + +#[no_mangle] +pub unsafe extern "C" fn __fprintf_chk(file: &FileStream, _flag: c_int, format: *const u8, mut args: ...) -> c_int { + let mut sink = WriteCounter(file, 0); + + let result = libuwuc::fmt::printf::printf_generic( + &mut sink, + SharedThinCstr::from_raw(format), + args.as_va_list(), + ); + + match result { + Ok(()) => sink.1 as _, + Err(err) => err, + } +} + +#[no_mangle] +pub unsafe extern "C" fn fprintf(file: &FileStream, format: *const u8, mut args: ...) -> c_int { + let mut sink = WriteCounter(file, 0); + + let result = libuwuc::fmt::printf::printf_generic( + &mut sink, + SharedThinCstr::from_raw(format), + args.as_va_list(), + ); + + match result { + Ok(()) => sink.1 as _, + Err(err) => err, + } +} + + // STREAMS: #[no_mangle]