This is Unofficial EPICS BASE Doxygen Site
osdStdio.c
Go to the documentation of this file.
1 /* osdStdio.c */
2 /*************************************************************************\
3 * Copyright (c) 2013 UChicago Argonne LLC, as Operator of Argonne
4 * National Laboratory.
5 * Copyright (c) 2002 The Regents of the University of California, as
6 * Operator of Los Alamos National Laboratory.
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 #include <string.h>
12 #include <vxWorks.h>
13 #include <fioLib.h>
14 #include "epicsStdio.h"
15 #include "dbDefs.h"
16 
17 struct outStr_s {
18  char *str;
19  size_t free;
20 };
21 
22 static STATUS outRoutine(char *buffer, size_t nchars, int outarg) {
23  struct outStr_s *poutStr = (struct outStr_s *) outarg;
24  size_t free = poutStr->free;
25  size_t len;
26 
27  if (free < 1) { /*let fioFormatV continue to count length*/
28  return OK;
29  } else if (free > 1) {
30  len = min(free-1, nchars);
31  strncpy(poutStr->str, buffer, len);
32  poutStr->str += len;
33  poutStr->free -= len;
34  }
35  /*make sure final string is null terminated*/
36  *poutStr->str = 0;
37  return OK;
38 }
39 
40 int epicsVsnprintf(char *str, size_t size, const char *format, va_list ap) {
41  struct outStr_s outStr;
42 
43  outStr.str = str;
44  outStr.free = size;
45  return fioFormatV(format, ap, outRoutine, (int) &outStr);
46 }
47 
48 int epicsSnprintf(char *str, size_t size, const char *format, ...)
49 {
50  size_t nchars;
51  va_list pvar;
52 
53  va_start(pvar,format);
54  nchars = epicsVsnprintf(str,size,format,pvar);
55  va_end (pvar);
56  return(nchars);
57 }
#define min(x, y)
Definition: flexdef.h:78
size_t free
Definition: osdStdio.c:19
Miscellaneous macro definitions.
LIBCOM_API int epicsStdCall epicsSnprintf(char *str, size_t size, const char *format,...)
Definition: osdStdio.c:14
LIBCOM_API int epicsStdCall epicsVsnprintf(char *str, size_t size, const char *format, va_list ap)
Definition: osdStdio.c:26
char * str
Definition: osdStdio.c:18