summaryrefslogtreecommitdiff
path: root/src/user/lib/libc/std/stdio.c
blob: 23ec989168d777bea016f0a83a110ba76309e14b (plain) (blame)
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
31
32
33
34
35
36
#include <stdlib.h>
#include <stdio.h>
#include <tce/syscall.h>
#include <readline.h>

FILE term = 0;
void print(const char *s) { fprint(term, s); }
void printf(const char *format,  ...) {
	va_list ap;
	va_start(ap, format);
	vfprintf(term, format, ap);
	va_end(ap);
}
char* readln() { return freadln(term); }

void fprint(FILE f, const char *s) {
	write(f, 0, strlen(s), s);
}

void fprintf(FILE f, const char* format, ...) {
	va_list ap;
	va_start(ap, format);
	vfprintf(f, format, ap);
	va_end(ap);
}

void vfprintf(FILE f, const char *fmt, va_list ap) {
	va_list ap2;
	va_copy(ap2, ap);
	int l = printf_str_len(fmt, ap2);
	va_end(ap2);
	char* buf = (char*) malloc(l+1);
	l = vsprintf(buf, fmt, ap);
	if (l > 0) write(f, 0, l, buf);
	free(buf);
}