summaryrefslogtreecommitdiff
path: root/lib/libc/stdio.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio.c')
-rw-r--r--lib/libc/stdio.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/libc/stdio.c b/lib/libc/stdio.c
new file mode 100644
index 0000000..70cc685
--- /dev/null
+++ b/lib/libc/stdio.c
@@ -0,0 +1,30 @@
+#include <libc/stdio.h>
+#include <libc/string.h>
+#include <posix/unistd.h>
+
+struct FILE
+{
+ int fd;
+};
+
+static FILE stdin_stream = { STDIN_FILENO };
+static FILE stdout_stream = { STDOUT_FILENO };
+static FILE stderr_stream = { STDERR_FILENO };
+
+FILE *stdin = &stdin_stream;
+FILE *stdout = &stdout_stream;
+FILE *stderr = &stderr_stream;
+
+int fputc(int c, FILE *f)
+{
+ write(f->fd, (const char *)&c, 1);
+ return 1;
+}
+
+int fputs(const char *s, FILE *f)
+{
+ size_t slen = strlen(s);
+ write(f->fd, s, slen);
+ return (int)slen;
+}
+