#include <defs.h>
#include <stdio.h>
#include <syscall.h>
#include <file.h>
#include <ulib.h>
#include <unistd.h>
static void
cputch(int c, int *cnt) {
sys_putc(c);
(*cnt) ++;
}
int
vcprintf(const char *fmt, va_list ap) {
int cnt = 0;
vprintfmt((void*)cputch, NO_FD, &cnt, fmt, ap);
return cnt;
}
int
cprintf(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
int cnt = vcprintf(fmt, ap);
va_end(ap);
return cnt;
}
int
cputs(const char *str) {
int cnt = 0;
char c;
while ((c = *str ++) != '\0') {
cputch(c, &cnt);
}
cputch('\n', &cnt);
return cnt;
}
static void
fputch(char c, int *cnt, int fd) {
write(fd, &c, sizeof(char));
(*cnt) ++;
}
int
vfprintf(int fd, const char *fmt, va_list ap) {
int cnt = 0;
vprintfmt((void*)fputch, fd, &cnt, fmt, ap);
return cnt;
}
int
fprintf(int fd, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
int cnt = vfprintf(fd, fmt, ap);
va_end(ap);
return cnt;
}