epicsStdio is new
This commit is contained in:
@@ -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
|
||||
|
||||
50
src/libCom/osi/os/WIN32/epicsStdio.c
Normal file
50
src/libCom/osi/os/WIN32/epicsStdio.c
Normal file
@@ -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 <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#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<size) return(rtn);
|
||||
if(rtn==-1) {
|
||||
str[size-1] = 0;
|
||||
return(size);
|
||||
}
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
int epicsShareAPI epicsSnprintf(
|
||||
char *str, size_t size, const char *format, ...)
|
||||
{
|
||||
int rtn;
|
||||
va_list pvar;
|
||||
|
||||
va_start(pvar, pFormat);
|
||||
rtn = epicsVsnprintf(str,size,format,pvar);
|
||||
va_end(pvar)
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
32
src/libCom/osi/os/WIN32/epicsStdio.h
Normal file
32
src/libCom/osi/os/WIN32/epicsStdio.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* epicsStdio.h */
|
||||
/*************************************************************************\
|
||||
* 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 <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#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 */
|
||||
18
src/libCom/osi/os/posix/epicsStdio.h
Normal file
18
src/libCom/osi/os/posix/epicsStdio.h
Normal file
@@ -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 <stdio.h>
|
||||
|
||||
#define epicsVsnprintf vsnprintf
|
||||
#define epicsSnprintf snprintf
|
||||
|
||||
#endif /* epicsStdioh */
|
||||
31
src/libCom/osi/os/vxWorks/epicsStdio.c
Normal file
31
src/libCom/osi/os/vxWorks/epicsStdio.c
Normal file
@@ -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);
|
||||
}
|
||||
27
src/libCom/osi/os/vxWorks/epicsStdio.h
Normal file
27
src/libCom/osi/os/vxWorks/epicsStdio.h
Normal file
@@ -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 <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#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 */
|
||||
@@ -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
|
||||
|
||||
67
src/libCom/test/epicsStdioTest.c
Normal file
67
src/libCom/test/epicsStdioTest.c
Normal file
@@ -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 <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
23
src/libCom/test/epicsStdioTestMain.cpp
Normal file
23
src/libCom/test/epicsStdioTestMain.cpp
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user