stdio.c (732B)
1 /* 2 * libc/stdio.c 3 * 4 * Copyright (C) 2009 stateless 5 */ 6 7 #include <tty.h> 8 #include <stdio.h> 9 #include <string.h> 10 #include <x86.h> 11 12 int 13 putchar(int c) 14 { 15 uint32_t state; 16 17 save_flags(&state); 18 cli(); 19 c = tty_putchar(c); 20 load_flags(state); 21 return c; 22 } 23 24 int 25 printf(const char *fmt, ...) 26 { 27 char buffer[512], *ptr; 28 va_list ap; 29 int c; 30 uint32_t state; 31 32 save_flags(&state); 33 cli(); 34 va_start(ap, fmt); 35 vsprintf(buffer, fmt, ap); 36 va_end(ap); 37 ptr = buffer; 38 while (*ptr) { 39 putchar(*ptr++); 40 ++c; 41 } 42 load_flags(state); 43 return c; 44 } 45 46 int 47 puts(const char *s) 48 { 49 uint32_t state; 50 51 save_flags(&state); 52 cli(); 53 const char *ptr = s; 54 while (*ptr) 55 putchar(*ptr++); 56 putchar('\n'); 57 load_flags(state); 58 return (int)(ptr - s); 59 } 60