1 // Copyright 2016 The Fuchsia Authors
2 // Copyright (c) 2013 Travis Geiselbrecht
3 //
4 // Use of this source code is governed by a MIT-style
5 // license that can be found in the LICENSE file or at
6 // https://opensource.org/licenses/MIT
7
8 #include <debug.h>
9 #include <stdio.h>
10 #include <stdarg.h>
11 #include <string.h>
12 #include <sys/types.h>
13 #include <platform/debug.h>
14
putchar(int c)15 int putchar(int c) {
16 platform_dputc(c);
17 return c;
18 }
19
puts(const char * str)20 int puts(const char *str) {
21 int len = strlen(str);
22 platform_dputs_thread(str, len);
23 return len;
24 }
25
getchar(void)26 int getchar(void)
27 {
28 char c;
29 int err = platform_dgetc(&c, true);
30 if (err < 0) {
31 return err;
32 } else {
33 return c;
34 }
35 }
36
37 extern int __printf_output_func(const char *str, size_t len, void *state);
38
_printf(const char * fmt,...)39 int _printf(const char *fmt, ...)
40 {
41 va_list ap;
42 int err;
43
44 va_start(ap, fmt);
45 err = _printf_engine(__printf_output_func, NULL, fmt, ap);
46 va_end(ap);
47
48 return err;
49 }
50
51
_vprintf(const char * fmt,va_list ap)52 int _vprintf(const char *fmt, va_list ap)
53 {
54 return _printf_engine(__printf_output_func, NULL, fmt, ap);
55 }
56