1 /* 2 * Copyright 2003-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <boot/vfs.h> 8 #include <boot/stdio.h> 9 #include <util/kernel_cpp.h> 10 11 #include <stdarg.h> 12 #include <string.h> 13 14 //#undef stdout 15 //#undef stdin 16 //extern FILE *stdout; 17 //extern FILE *stdin; 18 19 int errno; 20 int *_errnop = &errno; 21 22 23 int 24 vfprintf(FILE *file, const char *format, va_list list) 25 { 26 ConsoleNode *node = (ConsoleNode *)file; 27 char buffer[512]; 28 // the buffer handling could (or should) be done better... 29 30 int length = vsnprintf(buffer, sizeof(buffer), format, list); 31 if (length > 0) 32 node->Write(buffer, length); 33 34 return length; 35 } 36 37 38 int 39 vprintf(const char *format, va_list args) 40 { 41 return vfprintf(stdout, format, args); 42 } 43 44 45 int 46 printf(const char *format, ...) 47 { 48 va_list args; 49 50 va_start(args, format); 51 int status = vfprintf(stdout, format, args); 52 va_end(args); 53 54 return status; 55 } 56 57 58 int 59 fprintf(FILE *file, const char *format, ...) 60 { 61 va_list args; 62 63 va_start(args, format); 64 int status = vfprintf(file, format, args); 65 va_end(args); 66 67 return status; 68 } 69 70 71 int 72 fputc(int c, FILE *file) 73 { 74 if (file == NULL) 75 return B_FILE_ERROR; 76 77 status_t status; 78 char character = (char)c; 79 80 // we only support direct console output right now... 81 status = ((ConsoleNode *)file)->Write(&character, 1); 82 83 if (status > 0) 84 return character; 85 86 return status; 87 } 88 89 90 int 91 fputs(const char *string, FILE *file) 92 { 93 if (file == NULL) 94 return B_FILE_ERROR; 95 96 status_t status = ((ConsoleNode *)file)->Write(string, strlen(string)); 97 fputc('\n', file); 98 99 return status; 100 } 101 102 103 int 104 putc(int character) 105 { 106 return fputc(character, stdout); 107 } 108 109 110 int 111 putchar(int character) 112 { 113 return fputc(character, stdout); 114 } 115 116 117 int 118 puts(const char *string) 119 { 120 return fputs(string, stdout); 121 } 122 123