From 023cf2c548dbfcd372200c9f85ce8d44d82a5d36 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 22 Dec 2009 23:47:19 +0000 Subject: [PATCH] Added redirection support for puts() and putchar(). --- src/libCom/osi/epicsStdio.c | 30 ++++++++++++++++++++--------- src/libCom/osi/epicsStdio.h | 11 +++++++---- src/libCom/osi/epicsStdioRedirect.h | 26 ++++++++++++++++++------- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/libCom/osi/epicsStdio.c b/src/libCom/osi/epicsStdio.c index 288683f7d..50c696a2c 100644 --- a/src/libCom/osi/epicsStdio.c +++ b/src/libCom/osi/epicsStdio.c @@ -1,14 +1,15 @@ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found +* EPICS BASE is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ -/*epicsStdio.c*/ -/*Author: Marty Kraimer*/ + +/* epicsStdio.c */ + +/* Author: Marty Kraimer */ #include #include @@ -91,13 +92,24 @@ void epicsShareAPI epicsSetThreadStderr(FILE *fp) epicsThreadPrivateSet(stderrThreadPrivateId,fp); } -int epicsShareAPI epicsShareAPI epicsStdoutPrintf(const char *pFormat, ...) +int epicsShareAPI epicsStdoutPrintf(const char *pFormat, ...) { va_list pvar; int nchar; FILE *stream = epicsGetStdout(); + va_start(pvar, pFormat); - nchar = vfprintf(stream,pFormat,pvar); - va_end (pvar); - return(nchar); + nchar = vfprintf(stream, pFormat, pvar); + va_end(pvar); + return nchar; +} + +int epicsShareAPI epicsStdoutPuts(const char *str) +{ + return fprintf(epicsGetStdout(), "%s\n", str); +} + +int epicsShareAPI epicsStdoutPutchar(int c) +{ + return putc(c, epicsGetStdout()); } diff --git a/src/libCom/osi/epicsStdio.h b/src/libCom/osi/epicsStdio.h index b833b8dc2..7a2dc5ade 100644 --- a/src/libCom/osi/epicsStdio.h +++ b/src/libCom/osi/epicsStdio.h @@ -1,13 +1,14 @@ -/* epicsStdio.h */ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found +* EPICS BASE is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ + +/* epicsStdio.h */ + #ifndef epicsStdioh #define epicsStdioh @@ -57,6 +58,8 @@ epicsShareFunc void epicsShareAPI epicsSetThreadStderr(FILE *); epicsShareFunc int epicsShareAPI epicsStdoutPrintf( const char *pformat, ...) EPICS_PRINTF_STYLE(1,2); +epicsShareFunc int epicsShareAPI epicsStdoutPuts(const char *str); +epicsShareFunc int epicsShareAPI epicsStdoutPutchar(int c); #ifdef __cplusplus } diff --git a/src/libCom/osi/epicsStdioRedirect.h b/src/libCom/osi/epicsStdioRedirect.h index f335ecafc..36edf1dbe 100644 --- a/src/libCom/osi/epicsStdioRedirect.h +++ b/src/libCom/osi/epicsStdioRedirect.h @@ -1,13 +1,14 @@ -/* epicsStdioRedirect.h */ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found +* EPICS BASE is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ + +/* epicsStdioRedirect.h */ + #ifndef epicsStdioRedirecth #define epicsStdioRedirecth @@ -24,12 +25,23 @@ extern "C" { #undef stderr #define stderr epicsGetStderr() -/*The following are for making printf be fprintf(stdout */ +/* Make printf, puts and putchar use *our* version of stdout */ + #ifdef printf -#undef printf -#endif /*printf*/ +# undef printf +#endif /* printf */ #define printf epicsStdoutPrintf +#ifdef puts +# undef puts +#endif /* puts */ +#define puts epicsStdoutPuts + +#ifdef putchar +# undef putchar +#endif /* putchar */ +#define putchar epicsStdoutPutchar + #ifdef __cplusplus } #endif