Added redirection support for puts() and putchar().

This commit is contained in:
Andrew Johnson
2009-12-22 23:47:19 +00:00
parent b55cad9c16
commit 023cf2c548
3 changed files with 47 additions and 20 deletions

View File

@@ -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 <stdlib.h>
#include <stddef.h>
@@ -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());
}

View File

@@ -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
}

View File

@@ -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