summaryrefslogtreecommitdiff
path: root/lib/libc/stdio.c
blob: 70cc68576eb087fb10d1d31def6a4f1ce34db599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;
}