summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-10-26 13:59:06 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-10-28 13:33:55 +0200
commit7bec7f2715f0f3495f59513e61c319fe65a3fd40 (patch)
treeebd8253ec8fe2169ef6fcd2becd5cf7550f66796 /cpukit/libcsupport
parenttests: Move rtems_test_printer definition (diff)
downloadrtems-7bec7f2715f0f3495f59513e61c319fe65a3fd40.tar.bz2
rtems: Add rtems_print_printer_fprintf_putc()
Update #3170. Update #3199.
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r--cpukit/libcsupport/Makefile.am1
-rw-r--r--cpukit/libcsupport/src/printerfprintfputc.c67
2 files changed, 68 insertions, 0 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
index 66a8aa06da..8645ba1914 100644
--- a/cpukit/libcsupport/Makefile.am
+++ b/cpukit/libcsupport/Makefile.am
@@ -139,6 +139,7 @@ libcsupport_a_SOURCES = src/gxx_wrappers.c src/getchark.c src/printk.c \
$(BSD_LIBC_C_FILES) $(BASE_FS_C_FILES) $(MALLOC_C_FILES) \
$(ERROR_C_FILES) $(ASSOCIATION_C_FILES)
libcsupport_a_SOURCES += src/printertask.c
+libcsupport_a_SOURCES += src/printerfprintfputc.c
libcsupport_a_SOURCES += $(LIBC_GLUE_C_FILES) $(PASSWORD_GROUP_C_FILES) \
$(TERMINAL_IDENTIFICATION_C_FILES) $(SYSTEM_CALL_C_FILES) \
diff --git a/cpukit/libcsupport/src/printerfprintfputc.c b/cpukit/libcsupport/src/printerfprintfputc.c
new file mode 100644
index 0000000000..8b502fa489
--- /dev/null
+++ b/cpukit/libcsupport/src/printerfprintfputc.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2017 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/printer.h>
+#include <rtems/bspIo.h>
+
+#include <pthread.h>
+
+static pthread_once_t fprintf_putc_once = PTHREAD_ONCE_INIT;
+
+static FILE fprintf_putc_file;
+
+static _READ_WRITE_RETURN_TYPE fprintf_putc_write(
+ struct _reent *ptr,
+ void *cookie,
+ char const *buf,
+ _READ_WRITE_BUFSIZE_TYPE n
+)
+{
+ _READ_WRITE_RETURN_TYPE i;
+ _READ_WRITE_RETURN_TYPE m;
+
+ m = (_READ_WRITE_RETURN_TYPE) n;
+ for (i = 0; i < m; ++i) {
+ rtems_putc(buf[i]);
+ }
+
+ return m;
+}
+
+static void fprintf_putc_init(void)
+{
+ FILE *f;
+
+ f = &fprintf_putc_file;
+ f->_flags = __SWR | __SNBF;
+ f->_cookie = f;
+ f->_write = fprintf_putc_write;
+ __lock_init_recursive(f->_lock);
+}
+
+static int fprintf_putc_printer(void *context, const char *fmt, va_list ap)
+{
+ return vfprintf(context, fmt, ap);
+}
+
+void rtems_print_printer_fprintf_putc(rtems_printer *printer)
+{
+ pthread_once(&fprintf_putc_once, fprintf_putc_init);
+ printer->context = &fprintf_putc_file;
+ printer->printer = fprintf_putc_printer;
+}