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