ref: f801657f77f3923ec2388c25bdcb036c8019ba89
dir: /print.c/
#include <u.h> #include "mem.h" #include "dat.h" #include "fns.h" #include "libkern/kern.h" #define PRINTSIZE 256 int sprint(char *s, char *fmt, ...) { int n; va_list arg; va_start(arg, fmt); n = vseprint(s, s+PRINTSIZE, fmt, arg) - s; va_end(arg); return n; } int print(char *fmt, ...) { int n; va_list arg; char *t; char buf[PRINTSIZE]; va_start(arg, fmt); n = vseprint(buf, buf+sizeof(buf), fmt, arg) - buf; va_end(arg); t = buf; for (; ((uint)t - (uint)buf) < n; t++) { uart1_putc((int)*t); } return n; } void serwrite(char *msg, int n) { char buf[PRINTSIZE]; int c; while(n) { c = n; if(c > (PRINTSIZE - 1)) c = PRINTSIZE - 1; memcpy(buf, msg, c); buf[c] = 0; print(buf); n -= c; } }