Rename printk() to printf().
[pintos-anon] / src / lib / user / printf.c
1 #include <stdio.h>
2 #include <syscall.h>
3 #include <syscall-nr.h>
4
5 static void vprintf_helper (char, void *);
6
7 struct vprintf_aux 
8   {
9     char buf[64];
10     char *p;
11     int char_cnt;
12   };
13
14 int
15 vprintf (const char *format, va_list args) 
16 {
17   struct vprintf_aux aux;
18   aux.p = aux.buf;
19   aux.char_cnt = 0;
20   __vprintf (format, args, vprintf_helper, &aux);
21   if (aux.p > aux.buf)
22     write (STDOUT_FILENO, aux.buf, aux.p - aux.buf);
23   return aux.char_cnt;
24 }
25
26 /* Helper function for vprintf(). */
27 static void
28 vprintf_helper (char c, void *aux_) 
29 {
30   struct vprintf_aux *aux = aux_;
31   *aux->p++ = c;
32   if (aux->p >= aux->buf + sizeof aux->buf)
33     {
34       write (STDOUT_FILENO, aux->buf, aux->p - aux->buf);
35       aux->p = aux->buf;
36     }
37   aux->char_cnt++;
38 }
39
40 /* Writes C to the console. */
41 int
42 putchar (int c) 
43 {
44   char c2 = c;
45   write (STDOUT_FILENO, &c2, 1);
46   return c;
47 }