headers/bsd: Add sys/queue.h.
[haiku.git] / src / system / boot / loader / stdio.cpp
blob267ddbd46f70fc5e7b7f07d92378dd2925c7116d
1 /*
2 * Copyright 2003-2013, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <boot/vfs.h>
8 #include <boot/stdio.h>
10 #include <errno.h>
11 #include <stdarg.h>
12 #include <string.h>
14 #include <algorithm>
17 //#undef stdout
18 //#undef stdin
19 //extern FILE *stdout;
20 //extern FILE *stdin;
23 #undef errno
24 int errno;
27 int*
28 _errnop(void)
30 return &errno;
34 int
35 vfprintf(FILE *file, const char *format, va_list list)
37 ConsoleNode *node = (ConsoleNode *)file;
38 char buffer[512];
39 // the buffer handling could (or should) be done better...
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);
46 return length;
50 int
51 vprintf(const char *format, va_list args)
53 return vfprintf(stdout, format, args);
57 int
58 printf(const char *format, ...)
60 va_list args;
62 va_start(args, format);
63 int status = vfprintf(stdout, format, args);
64 va_end(args);
66 return status;
70 int
71 fprintf(FILE *file, const char *format, ...)
73 va_list args;
75 va_start(args, format);
76 int status = vfprintf(file, format, args);
77 va_end(args);
79 return status;
83 int
84 fputc(int c, FILE *file)
86 if (file == NULL)
87 return B_FILE_ERROR;
89 status_t status;
90 char character = (char)c;
92 // we only support direct console output right now...
93 status = ((ConsoleNode *)file)->Write(&character, 1);
95 if (status > 0)
96 return character;
98 return status;
103 fputs(const char *string, FILE *file)
105 if (file == NULL)
106 return B_FILE_ERROR;
108 status_t status = ((ConsoleNode *)file)->Write(string, strlen(string));
109 fputc('\n', file);
111 return status;
116 putc(int character)
118 return fputc(character, stdout);
123 putchar(int character)
125 return fputc(character, stdout);
130 puts(const char *string)
132 return fputs(string, stdout);