Module: xenomai-forge
Branch: master
Commit: a75aac05b2c144b6ab9aba573fb7f921ffc38c49
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=a75aac05b2c144b6ab9aba573fb7f921ffc38c49

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Apr 15 20:46:59 2012 +0200

rt_print: align with xenomai 2.6

fix puts, add fputc and putchar

---

 include/cobalt/stdio.h    |    8 ++++-
 include/rtdk.h            |    2 +
 lib/cobalt/posix.wrappers |    2 +
 lib/cobalt/printf.c       |   57 ++++++++++++++++++++++++++++++++++++++++++--
 lib/cobalt/wrappers.c     |   12 +++++++++
 5 files changed, 76 insertions(+), 5 deletions(-)

diff --git a/include/cobalt/stdio.h b/include/cobalt/stdio.h
index 7d161da..cadde58 100644
--- a/include/cobalt/stdio.h
+++ b/include/cobalt/stdio.h
@@ -22,9 +22,13 @@ COBALT_DECL(int, printf(const char *fmt, ...));
 
 COBALT_DECL(int, puts(const char *s));
 
-int __real_fputs(const char *s, FILE *stream);
+COBALT_DECL(int, fputs(const char *s, FILE *stream));
 
-size_t __real_fwrite(const void *ptr, size_t sz, size_t nmemb, FILE *stream);
+COBALT_DECL(int, fputc(int c, FILE *stream));
+
+COBALT_DECL(int, putchar(int c));
+
+COBALT_DECL(size_t, fwrite(const void *ptr, size_t sz, size_t nmemb, FILE 
*stream));
 
 #ifdef __cplusplus
 }
diff --git a/include/rtdk.h b/include/rtdk.h
index 398b1c9..1b5f218 100644
--- a/include/rtdk.h
+++ b/include/rtdk.h
@@ -54,6 +54,8 @@ int rt_fprintf(FILE *stream, const char *format, ...);
 int rt_printf(const char *format, ...);
 int rt_puts(const char *s);
 int rt_fputs(const char *s, FILE *stream);
+int rt_fputc(int c, FILE *stream);
+int rt_putchar(int c);
 size_t rt_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
 void rt_syslog(int priority, const char *format, ...);
 void rt_vsyslog(int priority, const char *format, va_list args);
diff --git a/lib/cobalt/posix.wrappers b/lib/cobalt/posix.wrappers
index bb18827..c5a15fb 100644
--- a/lib/cobalt/posix.wrappers
+++ b/lib/cobalt/posix.wrappers
@@ -87,6 +87,8 @@
 --wrap printf
 --wrap puts
 --wrap fputs
+--wrap fputc
+--wrap putchar
 --wrap fwrite
 --wrap syslog
 --wrap vsyslog
diff --git a/lib/cobalt/printf.c b/lib/cobalt/printf.c
index aeddd22..6654a93 100644
--- a/lib/cobalt/printf.c
+++ b/lib/cobalt/printf.c
@@ -274,7 +274,30 @@ int rt_fputs(const char *s, FILE *stream)
 
 int rt_puts(const char *s)
 {
-       return rt_fputs(s, stdout);
+       int res;
+
+       res = rt_fputs(s, stdout);
+       if (res < 0)
+               return res;
+
+       return print_to_buffer(stdout, 0, RT_PRINT_MODE_FWRITE, 1, "\n");
+}
+
+int rt_fputc(int c, FILE *stream)
+{
+       unsigned char uc = c;
+       int rc;
+
+       rc = print_to_buffer(stream, 0, RT_PRINT_MODE_FWRITE, 1, (char *)&uc);
+       if (rc < 0)
+               return EOF;
+
+       return (int)uc;
+}
+
+int rt_putchar(int c)
+{
+       return rt_fputc(c, stdout);
 }
 
 size_t rt_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
@@ -803,10 +826,38 @@ int __wrap_fputs(const char *s, FILE *stream)
 
 int __wrap_puts(const char *s)
 {
-       return __wrap_fputs(s, stdout);
+       if (unlikely(xeno_get_current() != XN_NO_HANDLE &&
+                    !(xeno_get_current_mode() & XNRELAX)))
+               return rt_puts(s);
+       else {
+               rt_print_flush_buffers();
+               return __real_puts(s);
+       }
+}
+
+int __wrap_fputc(int c, FILE *stream)
+{
+       if (unlikely(xeno_get_current() != XN_NO_HANDLE &&
+                    !(xeno_get_current_mode() & XNRELAX)))
+               return rt_fputc(c, stream);
+       else {
+               rt_print_flush_buffers();
+               return __real_fputc(c, stream);
+       }
+}
+
+int __wrap_putchar(int c)
+{
+       if (unlikely(xeno_get_current() != XN_NO_HANDLE &&
+                    !(xeno_get_current_mode() & XNRELAX)))
+               return rt_putchar(c);
+       else {
+               rt_print_flush_buffers();
+               return __real_putchar(c);
+       }
 }
 
-size_t __wrap_fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream)
+size_t __wrap_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
 {
        if (unlikely(xeno_get_current() != XN_NO_HANDLE &&
                     !(xeno_get_current_mode() & XNRELAX)))
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 272cfb4..90e0029 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -319,6 +319,18 @@ int __real_fputs(const char *s, FILE *stream)
 }
 
 __attribute__ ((weak))
+int __real_fputc(int c, FILE *stream)
+{
+       return fputc(c, stream);
+}
+
+__attribute__ ((weak))
+int __real_putchar(int c)
+{
+       return putchar(c);
+}
+
+__attribute__ ((weak))
 size_t __real_fwrite(const void *ptr, size_t sz, size_t nmemb, FILE *stream)
 {
        return fwrite(ptr, sz, nmemb, stream);


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to