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