summaryrefslogtreecommitdiff
path: root/src/user/lib/libc/std/stdio.c
blob: 12064be87028dbfec7516117b4d98f677012dc19 (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
37
#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);
}

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[l+1];
	l = vsprintf(buf, fmt, ap);
	if (l > 0) write(f, 0, l, buf);
}