ReactOS  0.4.15-dev-439-g292f67a
_sxprintf.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#include <tchar.h>
Include dependency graph for _sxprintf.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _tstreamout   streamout
 
#define min(a, b)   (((a) < (b)) ? (a) : (b))
 

Functions

int __cdecl _tstreamout (FILE *stream, const TCHAR *format, va_list argptr)
 
int __cdecl _sxprintf (TCHAR *buffer, const TCHAR *format,...)
 

Macro Definition Documentation

◆ _tstreamout

#define _tstreamout   streamout

Definition at line 20 of file _sxprintf.c.

◆ min

#define min (   a,
  b 
)    (((a) < (b)) ? (a) : (b))

Definition at line 23 of file _sxprintf.c.

Function Documentation

◆ _sxprintf()

int __cdecl _sxprintf ( TCHAR buffer,
const TCHAR format,
  ... 
)

Definition at line 33 of file _sxprintf.c.

47 {
48 #if !USE_COUNT
49  const size_t count = INT_MAX;
50 #endif
51 #if !IS_SECAPI
52  const size_t sizeOfBuffer = count;
53 #endif
54 #if !USE_VARARGS
55  va_list argptr;
56 #endif
57  int result;
58  FILE stream;
59 
60 #if IS_SECAPI
61  /* Validate parameters */
62  if (MSVCRT_CHECK_PMT(((buffer == NULL) || (format == NULL) || (sizeOfBuffer <= 0))))
63  {
64  errno = EINVAL;
65  return -1;
66  }
67 
68  /* Limit output to count + 1 characters */
69  if (count != -1)
71 #endif
72 
73  /* Setup the FILE structure */
74  stream._base = (char*)buffer;
75  stream._ptr = stream._base;
76  stream._charbuf = 0;
77  stream._cnt = (int)(sizeOfBuffer * sizeof(TCHAR));
78  stream._bufsiz = 0;
79  stream._flag = _IOSTRG | _IOWRT;
80  stream._tmpfname = 0;
81 
82 #if !USE_VARARGS
83  va_start(argptr, format);
84 #endif
85  result = _tstreamout(&stream, format, argptr);
86 #if !USE_VARARGS
87  va_end(argptr);
88 #endif
89 
90 #if IS_SECAPI
91  /* Check for failure or unterminated string */
92  if ((result < 0) || (result == sizeOfBuffer))
93  {
94  /* Null-terminate the buffer at the end */
95  buffer[sizeOfBuffer-1] = _T('\0');
96 
97  /* Check if we can truncate */
98  if (count != _TRUNCATE)
99  {
100  /* We can't, invoke invalid parameter handler */
101  MSVCRT_INVALID_PMT("Buffer is too small", ERANGE);
102 
103  /* If we came back, set the buffer to an empty string */
104  *buffer = 0;
105  }
106 
107  /* Return failure */
108  return -1;
109  }
110 
111  /* Null-terminate the buffer after the string */
112  buffer[result] = _T('\0');
113 #else
114  /* Only zero terminate if there is enough space left */
115  if ((stream._cnt >= sizeof(TCHAR)) && (stream._ptr))
116  *(TCHAR*)stream._ptr = _T('\0');
117 #endif
118 
119  return result;
120 }
#define INT_MAX
Definition: limits.h:40
Definition: arc.h:39
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
int errno
#define _IOSTRG
Definition: stdio.h:135
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define va_end(ap)
Definition: acmsvcex.h:90
#define MSVCRT_INVALID_PMT(x)
Definition: mbstowcs_s.c:25
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
#define _TRUNCATE
Definition: crtdefs.h:241
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define _IOWRT
Definition: stdio.h:126
#define ERANGE
Definition: acclib.h:92
Definition: parse.h:22
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
GLuint GLuint stream
Definition: glext.h:7522
#define _tstreamout
Definition: _sxprintf.c:20
#define min(a, b)
Definition: _sxprintf.c:23
#define va_start(ap, A)
Definition: acmsvcex.h:91
GLuint64EXT * result
Definition: glext.h:11304
static size_t sizeOfBuffer
Definition: printf.c:66
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

◆ _tstreamout()

int __cdecl _tstreamout ( FILE stream,
const TCHAR format,
va_list  argptr 
)