cfi new: fix new disabling buffer support
[barebox-mini2440.git] / common / console_simple.c
blob7695e05ecb60af621844abe54e56ba86db242950
1 #include <config.h>
2 #include <common.h>
3 #include <fs.h>
4 #include <errno.h>
6 static struct console_device *console;
8 int printf (const char *fmt, ...)
10 va_list args;
11 uint i;
12 char printbuffer[CFG_PBSIZE];
14 va_start (args, fmt);
16 /* For this to work, printbuffer must be larger than
17 * anything we ever want to print.
19 i = vsprintf (printbuffer, fmt, args);
20 va_end (args);
22 /* Print the string */
23 puts(printbuffer);
25 return i;
27 EXPORT_SYMBOL(printf);
29 int vprintf (const char *fmt, va_list args)
31 uint i;
32 char printbuffer[CFG_PBSIZE];
34 /* For this to work, printbuffer must be larger than
35 * anything we ever want to print.
37 i = vsprintf (printbuffer, fmt, args);
39 /* Print the string */
40 puts (printbuffer);
42 return i;
44 EXPORT_SYMBOL(vprintf);
46 void console_puts(unsigned int ch, const char *str)
48 const char *s = str;
49 while (*s) {
50 console_putc(ch, *s);
51 if (*s == '\n')
52 console_putc(ch, '\r');
53 s++;
56 EXPORT_SYMBOL(console_puts);
58 void console_putc(unsigned int ch, char c)
60 if (!console)
61 return;
63 console->putc(console, c);
64 if (c == '\n')
65 console->putc(console, '\r');
67 EXPORT_SYMBOL(console_putc);
69 int fputc(int fd, char c)
71 if (fd == 1)
72 putchar(c);
73 else if (fd == 2)
74 eputc(c);
75 else
76 return write(fd, &c, 1);
77 return 0;
79 EXPORT_SYMBOL(fputc);
81 int fputs(int fd, const char *s)
83 if (fd == 1)
84 puts(s);
85 else if (fd == 2)
86 eputs(s);
87 else
88 return write(fd, s, strlen(s));
89 return 0;
91 EXPORT_SYMBOL(fputs);
93 int tstc(void)
95 if (!console)
96 return 0;
98 return console->tstc(console);
100 EXPORT_SYMBOL(tstc);
102 int getc(void)
104 if (!console)
105 return -EINVAL;
106 return console->getc(console);
108 EXPORT_SYMBOL(getc);
110 void console_flush(void)
112 if (console && console->flush)
113 console->flush(console);
115 EXPORT_SYMBOL(console_flush);
117 #ifndef ARCH_HAS_CTRLC
118 /* test if ctrl-c was pressed */
119 int ctrlc (void)
121 if (tstc() && getc() == 3)
122 return 1;
123 return 0;
125 EXPORT_SYMBOL(ctrlc);
126 #endif /* ARCH_HAS_CTRC */
128 int console_register(struct console_device *newcdev)
130 if (!console)
131 console = newcdev;
132 return 0;