summaryrefslogtreecommitdiffstats
path: root/src/c/stdio.rs
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2019-08-09 21:13:19 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2019-08-09 21:13:19 +0200
commit69c9e6031abc309bd801e798a0d5d530f1e893a7 (patch)
tree13e4d571508082d8738d68c5fe7a5339482bceb4 /src/c/stdio.rs
parent0abdc827c9aa9e3f64d31d62663ea232863e4e76 (diff)
downloadneco-69c9e6031abc309bd801e798a0d5d530f1e893a7.tar
neco-69c9e6031abc309bd801e798a0d5d530f1e893a7.zip
WIP
Diffstat (limited to 'src/c/stdio.rs')
-rw-r--r--src/c/stdio.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/c/stdio.rs b/src/c/stdio.rs
new file mode 100644
index 0000000..aa824ed
--- /dev/null
+++ b/src/c/stdio.rs
@@ -0,0 +1,38 @@
+use core::fmt;
+
+use super::posix;
+use super::string;
+
+pub struct OStream {
+ file: *mut libc::FILE
+}
+
+pub fn stdout() -> OStream {
+ OStream { file: unsafe { posix::stdout } }
+}
+
+impl OStream {
+ pub fn write(&mut self, b: &[u8]) {
+ unsafe {
+ libc::fwrite(
+ b.as_ptr() as *const libc::c_void,
+ 1,
+ b.len(),
+ self.file,
+ );
+ }
+ }
+
+ pub fn puts(&mut self, s: &string::CStr) {
+ unsafe {
+ libc::fputs(s.as_ptr(), self.file);
+ }
+ }
+}
+
+impl fmt::Write for OStream {
+ fn write_str(&mut self, s: &str) -> fmt::Result {
+ self.write(s.as_bytes());
+ Ok(())
+ }
+}