use crate as libc; use crate::string; use core::fmt; pub struct OStream { file: *mut libc::FILE } #[inline] pub unsafe fn stdout() -> OStream { OStream { file: libc::stdout } } #[inline] pub unsafe fn stderr() -> OStream { OStream { file: libc::stderr } } impl OStream { #[inline] pub fn write(&mut self, b: &[u8]) { unsafe { libc::fwrite( b.as_ptr().cast(), 1, b.len(), self.file, ); } } #[inline] pub fn puts(&mut self, s: &string::CStr) { unsafe { libc::fputs(s.as_ptr(), self.file); } } } impl fmt::Write for OStream { #[inline] fn write_str(&mut self, s: &str) -> fmt::Result { self.write(s.as_bytes()); Ok(()) } }