summaryrefslogblamecommitdiff
path: root/src/user/lib/libc/std/stdio.c
blob: 196c5545ef6a66b07f74551986374877cf475cd3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                   
                  
                        
                     
 
              



                           
                                       

                             
                                   

                   
 




                                               

                             
                                


                   








                                                    
 
#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 = (char*) malloc(l+1);
	l = vsprintf(buf, fmt, ap);
	if (l > 0) write(f, 0, l, buf);
	free(buf);
}