ReactOS 0.4.15-dev-7906-g1b85a5f
_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;
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 _tstreamout
Definition: _sxprintf.c:20
#define min(a, b)
Definition: _sxprintf.c:23
#define EINVAL
Definition: acclib.h:90
#define ERANGE
Definition: acclib.h:92
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define _TRUNCATE
Definition: crtdefs.h:262
#define NULL
Definition: types.h:112
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLuint buffer
Definition: glext.h:5915
GLuint64EXT * result
Definition: glext.h:11304
#define INT_MAX
Definition: limits.h:40
#define _IOWRT
Definition: stdio.h:125
#define _IOSTRG
Definition: stdio.h:134
#define MSVCRT_INVALID_PMT(x)
Definition: mbstowcs_s.c:25
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
static size_t sizeOfBuffer
Definition: printf.c:68
#define errno
Definition: errno.h:18
Definition: parse.h:23
#define _T(x)
Definition: vfdio.h:22
char TCHAR
Definition: xmlstorage.h:189

◆ _tstreamout()

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