EPICS Base  7.0.5.1
epicsStdio.h
1 /*************************************************************************\
2 * Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * SPDX-License-Identifier: EPICS
7 * EPICS BASE is distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 
11 /* epicsStdio.h */
12 
13 #ifndef epicsStdioh
14 #define epicsStdioh
15 
16 #include <stdio.h>
17 #include <stdarg.h>
18 
19 #include "libComAPI.h"
20 #include "compilerDependencies.h"
21 #include "epicsTempFile.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #ifndef epicsStdioStdStreams
28 # undef stdin
29 # define stdin epicsGetStdin()
30 # undef stdout
31 # define stdout epicsGetStdout()
32 # undef stderr
33 # define stderr epicsGetStderr()
34 #endif
35 
36 /* Make printf, puts and putchar use *our* version of stdout */
37 
38 #ifndef epicsStdioStdPrintfEtc
39 # ifdef printf
40 # undef printf
41 # endif
42 # define printf epicsStdoutPrintf
43 
44 # ifdef puts
45 # undef puts
46 # endif
47 # define puts epicsStdoutPuts
48 
49 # ifdef putchar
50 # undef putchar
51 # endif
52 # define putchar epicsStdoutPutchar
53 #endif
54 
55 LIBCOM_API int epicsStdCall epicsSnprintf(
56  char *str, size_t size, const char *format, ...) EPICS_PRINTF_STYLE(3,4);
57 LIBCOM_API int epicsStdCall epicsVsnprintf(
58  char *str, size_t size, const char *format, va_list ap);
59 
60 /*
61  * truncate to specified size (we dont use truncate()
62  * because it is not portable)
63  *
64  * pFileName - name (and optionally path) of file
65  * size - the new file size (if file is curretly larger)
66  *
67  * returns TF_OK if the file is less than size bytes
68  * or if it was successfully truncated. Returns
69  * TF_ERROR if the file could not be truncated.
70  */
71 enum TF_RETURN {TF_OK=0, TF_ERROR=1};
72 LIBCOM_API enum TF_RETURN truncateFile ( const char *pFileName, unsigned long size );
73 
74 /* The following are for redirecting stdin,stdout,stderr */
75 LIBCOM_API FILE * epicsStdCall epicsGetStdin(void);
76 LIBCOM_API FILE * epicsStdCall epicsGetStdout(void);
77 LIBCOM_API FILE * epicsStdCall epicsGetStderr(void);
78 /* These are intended for iocsh only */
79 LIBCOM_API FILE * epicsStdCall epicsGetThreadStdin(void);
80 LIBCOM_API FILE * epicsStdCall epicsGetThreadStdout(void);
81 LIBCOM_API FILE * epicsStdCall epicsGetThreadStderr(void);
82 LIBCOM_API void epicsStdCall epicsSetThreadStdin(FILE *);
83 LIBCOM_API void epicsStdCall epicsSetThreadStdout(FILE *);
84 LIBCOM_API void epicsStdCall epicsSetThreadStderr(FILE *);
85 
86 LIBCOM_API int epicsStdCall epicsStdoutPrintf(
87  const char *pformat, ...) EPICS_PRINTF_STYLE(1,2);
88 LIBCOM_API int epicsStdCall epicsStdoutPuts(const char *str);
89 LIBCOM_API int epicsStdCall epicsStdoutPutchar(int c);
90 
91 #ifdef __cplusplus
92 }
93 
94 /* Also pull functions into the std namespace (see lp:1786927) */
95 #if !defined(__GNUC__) || (__GNUC__ > 2)
96 namespace std {
97 using ::epicsGetStdin;
98 using ::epicsGetStdout;
99 using ::epicsGetStderr;
100 using ::epicsStdoutPrintf;
101 using ::epicsStdoutPuts;
102 using ::epicsStdoutPutchar;
103 }
104 #endif /* __GNUC__ > 2 */
105 
106 #endif /* __cplusplus */
107 
108 #endif /* epicsStdioh */
STL namespace.
Compiler specific declarations.
OS-independent way to create temporary files.