This is Unofficial EPICS BASE Doxygen Site
epicsStdio.h File Reference
#include <stdio.h>
#include <stdarg.h>
#include "libComAPI.h"
#include "compilerDependencies.h"
#include "epicsTempFile.h"
+ Include dependency graph for epicsStdio.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define stdin   epicsGetStdin()
 
#define stdout   epicsGetStdout()
 
#define stderr   epicsGetStderr()
 
#define printf   epicsStdoutPrintf
 
#define puts   epicsStdoutPuts
 
#define putchar   epicsStdoutPutchar
 

Enumerations

enum  TF_RETURN { TF_OK =0, TF_ERROR =1 }
 

Functions

LIBCOM_API int epicsStdCall epicsSnprintf (char *str, size_t size, const char *format,...) EPICS_PRINTF_STYLE(3
 
LIBCOM_API int epicsStdCall LIBCOM_API int epicsStdCall epicsVsnprintf (char *str, size_t size, const char *format, va_list ap)
 
LIBCOM_API enum TF_RETURN truncateFile (const char *pFileName, unsigned long size)
 
LIBCOM_API FILE *epicsStdCall epicsGetStdin (void)
 
LIBCOM_API FILE *epicsStdCall epicsGetStdout (void)
 
LIBCOM_API FILE *epicsStdCall epicsGetStderr (void)
 
LIBCOM_API FILE *epicsStdCall epicsGetThreadStdin (void)
 
LIBCOM_API FILE *epicsStdCall epicsGetThreadStdout (void)
 
LIBCOM_API FILE *epicsStdCall epicsGetThreadStderr (void)
 
LIBCOM_API void epicsStdCall epicsSetThreadStdin (FILE *)
 
LIBCOM_API void epicsStdCall epicsSetThreadStdout (FILE *)
 
LIBCOM_API void epicsStdCall epicsSetThreadStderr (FILE *)
 
LIBCOM_API int epicsStdCall epicsStdoutPrintf (const char *pformat,...) EPICS_PRINTF_STYLE(1
 
LIBCOM_API int epicsStdCall LIBCOM_API int epicsStdCall epicsStdoutPuts (const char *str)
 
LIBCOM_API int epicsStdCall epicsStdoutPutchar (int c)
 

Macro Definition Documentation

#define printf   epicsStdoutPrintf

Definition at line 41 of file epicsStdio.h.

#define putchar   epicsStdoutPutchar

Definition at line 51 of file epicsStdio.h.

#define puts   epicsStdoutPuts

Definition at line 46 of file epicsStdio.h.

#define stderr   epicsGetStderr()

Definition at line 32 of file epicsStdio.h.

#define stdin   epicsGetStdin()

Definition at line 28 of file epicsStdio.h.

#define stdout   epicsGetStdout()

Definition at line 30 of file epicsStdio.h.

Enumeration Type Documentation

enum TF_RETURN
Enumerator
TF_OK 
TF_ERROR 

Definition at line 70 of file epicsStdio.h.

70 {TF_OK=0, TF_ERROR=1};

Function Documentation

LIBCOM_API FILE* epicsStdCall epicsGetStderr ( void  )

Definition at line 56 of file epicsStdio.c.

57 {
58  FILE *fp = epicsGetThreadStderr();
59 
60  if (!fp)
61  fp = stderr;
62  return fp;
63 }
FILE *epicsStdCall epicsGetThreadStderr(void)
Definition: epicsStdio.c:77
#define stderr
Definition: epicsStdio.h:32
LIBCOM_API FILE* epicsStdCall epicsGetStdin ( void  )

Definition at line 38 of file epicsStdio.c.

39 {
40  FILE *fp = epicsGetThreadStdin();
41 
42  if (!fp)
43  fp = stdin;
44  return fp;
45 }
FILE *epicsStdCall epicsGetThreadStdin(void)
Definition: epicsStdio.c:65
#define stdin
Definition: epicsStdio.h:28
LIBCOM_API FILE* epicsStdCall epicsGetStdout ( void  )

Definition at line 47 of file epicsStdio.c.

48 {
49  FILE *fp = epicsGetThreadStdout();
50 
51  if (!fp)
52  fp = stdout;
53  return fp;
54 }
#define stdout
Definition: epicsStdio.h:30
FILE *epicsStdCall epicsGetThreadStdout(void)
Definition: epicsStdio.c:71
LIBCOM_API FILE* epicsStdCall epicsGetThreadStderr ( void  )

Definition at line 77 of file epicsStdio.c.

78 {
79  /* Deliberately don't do the epicsThreadOnce() here; epicsThreadInit()
80  * is allowed to use stderr inside its once() routine, in which case we
81  * must return the OS's stderr instead. There may be a tiny chance of a
82  * race happening here during initialization for some architectures, so
83  * we only use it for stderr to reduce the chance of that happening.
84  */
85  if (!stderrThreadPrivateId)
86  return NULL;
87  return epicsThreadPrivateGet(stderrThreadPrivateId);
88 }
LIBCOM_API void *epicsStdCall epicsThreadPrivateGet(epicsThreadPrivateId)
Definition: osdThread.c:973
#define NULL
Definition: catime.c:38
LIBCOM_API FILE* epicsStdCall epicsGetThreadStdin ( void  )

Definition at line 65 of file epicsStdio.c.

66 {
67  epicsThreadOnce(&onceId,once,0);
68  return epicsThreadPrivateGet(stdinThreadPrivateId);
69 }
LIBCOM_API void *epicsStdCall epicsThreadPrivateGet(epicsThreadPrivateId)
Definition: osdThread.c:973
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
LIBCOM_API FILE* epicsStdCall epicsGetThreadStdout ( void  )

Definition at line 71 of file epicsStdio.c.

72 {
73  epicsThreadOnce(&onceId,once,0);
74  return epicsThreadPrivateGet(stdoutThreadPrivateId);
75 }
LIBCOM_API void *epicsStdCall epicsThreadPrivateGet(epicsThreadPrivateId)
Definition: osdThread.c:973
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
LIBCOM_API void epicsStdCall epicsSetThreadStderr ( FILE *  )

Definition at line 102 of file epicsStdio.c.

103 {
104  epicsThreadOnce(&onceId,once,0);
105  epicsThreadPrivateSet(stderrThreadPrivateId,fp);
106 }
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
LIBCOM_API void epicsStdCall epicsThreadPrivateSet(epicsThreadPrivateId, void *)
Definition: osdThread.c:961
LIBCOM_API void epicsStdCall epicsSetThreadStdin ( FILE *  )

Definition at line 90 of file epicsStdio.c.

91 {
92  epicsThreadOnce(&onceId,once,0);
93  epicsThreadPrivateSet(stdinThreadPrivateId,fp);
94 }
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
LIBCOM_API void epicsStdCall epicsThreadPrivateSet(epicsThreadPrivateId, void *)
Definition: osdThread.c:961
LIBCOM_API void epicsStdCall epicsSetThreadStdout ( FILE *  )

Definition at line 96 of file epicsStdio.c.

97 {
98  epicsThreadOnce(&onceId,once,0);
99  epicsThreadPrivateSet(stdoutThreadPrivateId,fp);
100 }
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
LIBCOM_API void epicsStdCall epicsThreadPrivateSet(epicsThreadPrivateId, void *)
Definition: osdThread.c:961
LIBCOM_API int epicsStdCall epicsSnprintf ( char *  str,
size_t  size,
const char *  format,
  ... 
)
LIBCOM_API int epicsStdCall epicsStdoutPrintf ( const char *  pformat,
  ... 
)
LIBCOM_API int epicsStdCall epicsStdoutPutchar ( int  c)

Definition at line 125 of file epicsStdio.c.

126 {
127  return putc(c, epicsGetStdout());
128 }
FILE *epicsStdCall epicsGetStdout(void)
Definition: epicsStdio.c:47
LIBCOM_API int epicsStdCall LIBCOM_API int epicsStdCall epicsStdoutPuts ( const char *  str)

Definition at line 120 of file epicsStdio.c.

121 {
122  return fprintf(epicsGetStdout(), "%s\n", str);
123 }
#define str(v)
FILE *epicsStdCall epicsGetStdout(void)
Definition: epicsStdio.c:47
LIBCOM_API int epicsStdCall LIBCOM_API int epicsStdCall epicsVsnprintf ( char *  str,
size_t  size,
const char *  format,
va_list  ap 
)

Definition at line 26 of file osdStdio.c.

28 {
29  return vsnprintf ( str, size, format, ap );
30 }
#define str(v)
int vsnprintf(char *str, size_t size, const char *format, va_list ap)
LIBCOM_API enum TF_RETURN truncateFile ( const char *  pFileName,
unsigned long  size 
)

Definition at line 27 of file truncateFile.c.

28 {
29  long filePos;
30  FILE *pFile;
31  FILE *ptmp;
32  int status;
33  int c;
34  unsigned charNo;
35 
36  /*
37  * see cast of size to long below
38  */
39  if (size>LONG_MAX) {
40  return TF_ERROR;
41  }
42 
43  pFile = fopen(pFileName, "r");
44  if (!pFile) {
45  fprintf (stderr,
46  "File access problems to `%s' because `%s'\n",
47  pFileName,
48  strerror(errno));
49  return TF_ERROR;
50  }
51 
52  /*
53  * This is not required under UNIX but does appear
54  * to be required under WIN32.
55  */
56  status = fseek (pFile, 0L, SEEK_END);
57  if (status!=TF_OK) {
58  fclose (pFile);
59  return TF_ERROR;
60  }
61 
62  filePos = ftell(pFile);
63  if (filePos <= (long) size) {
64  fclose (pFile);
65  return TF_OK;
66  }
67 
68  ptmp = epicsTempFile();
69  if (!ptmp) {
70  fprintf (stderr,
71  "File access problems to temp file because `%s'\n",
72  strerror(errno));
73  fclose (pFile);
74  return TF_ERROR;
75  }
76  rewind (pFile);
77  charNo = 0u;
78  while (charNo<size) {
79  c = getc (pFile);
80  if (c==EOF) {
81  fprintf (stderr,
82  "File access problems to temp file because `%s'\n",
83  strerror(errno));
84  fclose (pFile);
85  fclose (ptmp);
86  return TF_ERROR;
87  }
88  status = putc (c, ptmp);
89  if (status==EOF) {
90  fprintf(stderr,
91  "File access problems to temp file because `%s'\n",
92  strerror(errno));
93  fclose (pFile);
94  fclose (ptmp);
95  return TF_ERROR;
96  }
97  charNo++;
98  }
99  fclose (pFile);
100  pFile = fopen(pFileName, "w");
101  if (!pFile) {
102  fprintf (stderr,
103  "File access problems to `%s' because `%s'\n",
104  pFileName,
105  strerror(errno));
106  fclose (ptmp);
107  return TF_ERROR;
108  }
109  rewind (ptmp);
110  charNo = 0u;
111  while (charNo<size) {
112  c = getc (ptmp);
113  if (c==EOF) {
114  fprintf (stderr,
115  "File access problems to temp file because `%s'\n",
116  strerror(errno));
117  fclose (pFile);
118  fclose (ptmp);
119  return TF_ERROR;
120  }
121  status = putc (c, pFile);
122  if (status==EOF) {
123  fprintf(stderr,
124  "File access problems to `%s' because `%s'\n",
125  pFileName,
126  strerror(errno));
127  fclose (pFile);
128  fclose (ptmp);
129  return TF_ERROR;
130  }
131  charNo++;
132  }
133  fclose(ptmp);
134  fclose(pFile);
135  return TF_OK;
136 }
#define SEEK_END
Definition: truncateFile.c:20
pvd::Status status
LIBCOM_API FILE *epicsStdCall epicsTempFile(void)
Create and open a temporary file.
Definition: epicsTempFile.c:15
#define stderr
Definition: epicsStdio.h:32