1 /* 2 * Copyright 2003-2005, 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 character, FILE *file) 73 { 74 if (file == NULL) 75 return B_FILE_ERROR; 76 77 status_t status; 78 79 // we only support direct console output right now... 80 status = ((ConsoleNode *)file)->Write(&character, 1); 81 82 if (status > 0) 83 return character; 84 85 return status; 86 } 87 88 89 int 90 fputs(const char *string, FILE *file) 91 { 92 if (file == NULL) 93 return B_FILE_ERROR; 94 95 status_t status = ((ConsoleNode *)file)->Write(string, strlen(string)); 96 fputc('\n', file); 97 98 return status; 99 } 100 101 102 int 103 putc(int character) 104 { 105 return fputc(character, stdout); 106 } 107 108 109 int 110 putchar(int character) 111 { 112 return fputc(character, stdout); 113 } 114 115 116 int 117 puts(const char *string) 118 { 119 return fputs(string, stdout); 120 } 121 122