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 #include <algorithm> 15 16 17 //#undef stdout 18 //#undef stdin 19 //extern FILE *stdout; 20 //extern FILE *stdin; 21 22 int errno; 23 int *_errnop = &errno; 24 25 26 int 27 vfprintf(FILE *file, const char *format, va_list list) 28 { 29 ConsoleNode *node = (ConsoleNode *)file; 30 char buffer[512]; 31 // the buffer handling could (or should) be done better... 32 33 int length = vsnprintf(buffer, sizeof(buffer), format, list); 34 length = std::min(length, (int)sizeof(buffer) - 1); 35 if (length > 0) 36 node->Write(buffer, length); 37 38 return length; 39 } 40 41 42 int 43 vprintf(const char *format, va_list args) 44 { 45 return vfprintf(stdout, format, args); 46 } 47 48 49 int 50 printf(const char *format, ...) 51 { 52 va_list args; 53 54 va_start(args, format); 55 int status = vfprintf(stdout, format, args); 56 va_end(args); 57 58 return status; 59 } 60 61 62 int 63 fprintf(FILE *file, const char *format, ...) 64 { 65 va_list args; 66 67 va_start(args, format); 68 int status = vfprintf(file, format, args); 69 va_end(args); 70 71 return status; 72 } 73 74 75 int 76 fputc(int c, FILE *file) 77 { 78 if (file == NULL) 79 return B_FILE_ERROR; 80 81 status_t status; 82 char character = (char)c; 83 84 // we only support direct console output right now... 85 status = ((ConsoleNode *)file)->Write(&character, 1); 86 87 if (status > 0) 88 return character; 89 90 return status; 91 } 92 93 94 int 95 fputs(const char *string, FILE *file) 96 { 97 if (file == NULL) 98 return B_FILE_ERROR; 99 100 status_t status = ((ConsoleNode *)file)->Write(string, strlen(string)); 101 fputc('\n', file); 102 103 return status; 104 } 105 106 107 int 108 putc(int character) 109 { 110 return fputc(character, stdout); 111 } 112 113 114 int 115 putchar(int character) 116 { 117 return fputc(character, stdout); 118 } 119 120 121 int 122 puts(const char *string) 123 { 124 return fputs(string, stdout); 125 } 126 127