1 | /* |
---|
2 | * Copyright (c) 2017 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/printer.h> |
---|
20 | #include <rtems/bspIo.h> |
---|
21 | |
---|
22 | #include <pthread.h> |
---|
23 | |
---|
24 | static pthread_once_t fprintf_putc_once = PTHREAD_ONCE_INIT; |
---|
25 | |
---|
26 | static FILE fprintf_putc_file; |
---|
27 | |
---|
28 | static _READ_WRITE_RETURN_TYPE fprintf_putc_write( |
---|
29 | struct _reent *ptr, |
---|
30 | void *cookie, |
---|
31 | char const *buf, |
---|
32 | _READ_WRITE_BUFSIZE_TYPE n |
---|
33 | ) |
---|
34 | { |
---|
35 | _READ_WRITE_RETURN_TYPE i; |
---|
36 | _READ_WRITE_RETURN_TYPE m; |
---|
37 | |
---|
38 | m = (_READ_WRITE_RETURN_TYPE) n; |
---|
39 | for (i = 0; i < m; ++i) { |
---|
40 | rtems_putc(buf[i]); |
---|
41 | } |
---|
42 | |
---|
43 | return m; |
---|
44 | } |
---|
45 | |
---|
46 | static void fprintf_putc_init(void) |
---|
47 | { |
---|
48 | FILE *f; |
---|
49 | |
---|
50 | f = &fprintf_putc_file; |
---|
51 | f->_flags = __SWR | __SNBF; |
---|
52 | f->_cookie = f; |
---|
53 | f->_write = fprintf_putc_write; |
---|
54 | __lock_init_recursive(f->_lock); |
---|
55 | } |
---|
56 | |
---|
57 | static int fprintf_putc_printer(void *context, const char *fmt, va_list ap) |
---|
58 | { |
---|
59 | return vfprintf(context, fmt, ap); |
---|
60 | } |
---|
61 | |
---|
62 | void rtems_print_printer_fprintf_putc(rtems_printer *printer) |
---|
63 | { |
---|
64 | pthread_once(&fprintf_putc_once, fprintf_putc_init); |
---|
65 | printer->context = &fprintf_putc_file; |
---|
66 | printer->printer = fprintf_putc_printer; |
---|
67 | } |
---|