diff --git a/src/libCom/Makefile b/src/libCom/Makefile index 8bc8c62a5..7bc91b26a 100644 --- a/src/libCom/Makefile +++ b/src/libCom/Makefile @@ -166,6 +166,7 @@ INC += osiUnistd.h INC += osiWireFormat.h INC += epicsReadline.h INC += epicsMessageQueue.h +INC += epicsStdio.h SRCS += epicsThread.cpp SRCS += epicsMutex.cpp @@ -218,10 +219,12 @@ INC_WIN32 := getopt.h SRCS_WIN32 := getopt.c SRCS_WIN32 += dllmain.cpp SRCS_WIN32 += forceBadAllocException.cpp +SRCS_WIN32 += epicsStdio.c # For vxWorks a clock INC_vxWorks += iocClock.h SRCS_vxWorks += iocClock.c +SRCS_vxWorks += epicsStdio.c # Library to build: # lib$(LIBRARY).a or ..dll/..exp/..lib diff --git a/src/libCom/osi/os/WIN32/epicsStdio.c b/src/libCom/osi/os/WIN32/epicsStdio.c new file mode 100644 index 000000000..c57ca0b79 --- /dev/null +++ b/src/libCom/osi/os/WIN32/epicsStdio.c @@ -0,0 +1,50 @@ +/* epicsStdio.c */ +/*************************************************************************\ +* Copyright (c) 2002 The University of Chicago, 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 +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define epicsExportSharedSymbols +#include "epicsStdio.h" + +int epicsShareAPI epicsVsnprintf( + char *str, size_t size, const char *format, va_list ap) +{ + int rtn; + + rtn = _vsnprintf(str,size,format,ap); + if(rtn>=0 && rtn +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#include "shareLib.h" + +epicsShareFunc int epicsShareAPI epicsSnprintf( + char *str, size_t size, const char *format, ...); +epicsShareFunc int epicsShareAPI epicsVsnprintf( + char *str, size_t size, const char *format, va_list ap); + +#ifdef __cplusplus +} +#endif + +#endif /* epicsStdioh */ diff --git a/src/libCom/osi/os/posix/epicsStdio.h b/src/libCom/osi/os/posix/epicsStdio.h new file mode 100644 index 000000000..dac7b78b0 --- /dev/null +++ b/src/libCom/osi/os/posix/epicsStdio.h @@ -0,0 +1,18 @@ +/*************************************************************************\ +* Copyright (c) 2002 The University of Chicago, 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 +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +#ifndef epicsStdioh +#define epicsStdioh + +#include + +#define epicsVsnprintf vsnprintf +#define epicsSnprintf snprintf + +#endif /* epicsStdioh */ diff --git a/src/libCom/osi/os/vxWorks/epicsStdio.c b/src/libCom/osi/os/vxWorks/epicsStdio.c new file mode 100644 index 000000000..773982212 --- /dev/null +++ b/src/libCom/osi/os/vxWorks/epicsStdio.c @@ -0,0 +1,31 @@ +/* epicsStdio.c */ +/*************************************************************************\ +* Copyright (c) 2002 The University of Chicago, 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 +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +#include "epicsStdio.h" + +int epicsVsnprintf(char *str, size_t size, const char *format, va_list ap) +{ + int nchars; + + nchars = vsprintf(str,format,ap); + return(nchars); +} + +int epicsSnprintf(char *str, size_t size, const char *format, ...) +{ + int nchars; + va_list pvar; + + va_start(pvar,format); + nchars = epicsVsnprintf(str,size,format,pvar); + va_end (pvar); + return(nchars); +} diff --git a/src/libCom/osi/os/vxWorks/epicsStdio.h b/src/libCom/osi/os/vxWorks/epicsStdio.h new file mode 100644 index 000000000..dffa06143 --- /dev/null +++ b/src/libCom/osi/os/vxWorks/epicsStdio.h @@ -0,0 +1,27 @@ +/*************************************************************************\ +* Copyright (c) 2002 The University of Chicago, 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 +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +#ifndef epicsStdioh +#define epicsStdioh + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int epicsSnprintf(char *str, size_t size, const char *format, ...); +int epicsVsnprintf(char *str, size_t size, const char *format, va_list ap); + +#ifdef __cplusplus +} +#endif + +#endif /* epicsStdioh */ diff --git a/src/libCom/test/Makefile b/src/libCom/test/Makefile index d13fa7b4f..d5f2e14f8 100644 --- a/src/libCom/test/Makefile +++ b/src/libCom/test/Makefile @@ -26,6 +26,10 @@ epicsMathTestHost_SRCS += epicsMathTestMain.cpp epicsMathTest.c PROD_HOST += epicsMathTestHost OBJS_IOC += epicsMathTest +epicsStdioTestHost_SRCS += epicsStdioTestMain.cpp epicsStdioTest.c +PROD_HOST += epicsStdioTestHost +OBJS_IOC += epicsStdioTest + epicsTimeTestHost_SRCS += epicsTimeTestMain.cpp epicsTimeTest.cpp PROD_HOST += epicsTimeTestHost OBJS_IOC += epicsTimeTest diff --git a/src/libCom/test/epicsStdioTest.c b/src/libCom/test/epicsStdioTest.c new file mode 100644 index 000000000..6ef1f28e9 --- /dev/null +++ b/src/libCom/test/epicsStdioTest.c @@ -0,0 +1,67 @@ +/*************************************************************************\ +* Copyright (c) 2002 The University of Chicago, 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 +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* epicsStdioTest.c + * + * Author Marty Kraimer + */ + +#include +#include +#include +#include +#include +#include + +#include "epicsStdio.h" + +static int xsnprintf(char *str, size_t size, const char *format, ...) +{ + int nchar; + va_list pvar; + + va_start(pvar,format); + nchar = epicsVsnprintf(str,size,format,pvar); + va_end (pvar); + return(nchar); +} + + +int epicsStdioTest () +{ + char buffer[20]; + int rtn; + int value = 10; + int size = 10; + + memset(buffer,'*',sizeof(buffer)-1); + buffer[sizeof(buffer)-1] = 0; + printf("at start buffer |%s|\n",buffer); + rtn = xsnprintf(buffer,size,"value is %d",value); + printf("size %d rtn %d value %d buffer |%s|\n",size,rtn,value,buffer); + memset(buffer,'*',sizeof(buffer)-1); + rtn = xsnprintf(buffer,size,"value: %d",value); + printf("size %d rtn %d value %d buffer |%s|\n",size,rtn,value,buffer); + memset(buffer,'*',sizeof(buffer)-1); + rtn = xsnprintf(buffer,size,"%d",value); + printf("size %d rtn %d value %d buffer |%s|\n",size,rtn,value,buffer); + + memset(buffer,'*',sizeof(buffer)-1); + buffer[sizeof(buffer)-1] = 0; + printf("at start buffer |%s|\n",buffer); + rtn = epicsSnprintf(buffer,size,"value is %d",value); + printf("size %d rtn %d value %d buffer |%s|\n",size,rtn,value,buffer); + memset(buffer,'*',sizeof(buffer)-1); + rtn = epicsSnprintf(buffer,size,"value: %d",value); + printf("size %d rtn %d value %d buffer |%s|\n",size,rtn,value,buffer); + memset(buffer,'*',sizeof(buffer)-1); + rtn = epicsSnprintf(buffer,size,"%d",value); + printf("size %d rtn %d value %d buffer |%s|\n",size,rtn,value,buffer); + return(0); +} diff --git a/src/libCom/test/epicsStdioTestMain.cpp b/src/libCom/test/epicsStdioTestMain.cpp new file mode 100644 index 000000000..648a1d352 --- /dev/null +++ b/src/libCom/test/epicsStdioTestMain.cpp @@ -0,0 +1,23 @@ +/*************************************************************************\ +* Copyright (c) 2002 The University of Chicago, 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 +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* epicsStdioTestMain.cpp + * + * Author Marty Kraimer + */ + +extern "C" { +int epicsStdioTest ( void ); +} + +int main ( int , char *[] ) +{ + epicsStdioTest (); + return 0; +}