mirror of
https://github.com/reactos/reactos.git
synced 2024-07-10 22:55:05 +00:00
[CRT]
Implement [v]s[nw]printf_s [MSVCRT] Enable [v]s[nw]printf_s exports svn path=/trunk/; revision=58515
This commit is contained in:
parent
cbed503fb8
commit
f4e6200805
|
@ -832,7 +832,7 @@
|
|||
# stub _snprintf_c
|
||||
# stub _snprintf_c_l
|
||||
# stub _snprintf_l
|
||||
# stub _snprintf_s
|
||||
@ varargs _snprintf_s(ptr long long ptr)
|
||||
# stub _snprintf_s_l
|
||||
# stub _snscanf
|
||||
# stub _snscanf_l
|
||||
|
@ -840,7 +840,7 @@
|
|||
# stub _snscanf_s_l
|
||||
@ varargs _snwprintf(ptr long wstr)
|
||||
# stub _snwprintf_l
|
||||
# stub _snwprintf_s
|
||||
@ varargs _snwprintf_s(ptr long long ptr)
|
||||
# stub _snwprintf_s_l
|
||||
# stub _snwscanf
|
||||
# stub _snwscanf_l
|
||||
|
@ -985,11 +985,11 @@
|
|||
@ cdecl _vsnprintf_c(ptr long str ptr) _vsnprintf
|
||||
# @ cdecl _vsnprintf_c_l(ptr long str ptr ptr) _vsnprintf_l
|
||||
# @ cdecl _vsnprintf_l(ptr long str ptr ptr)
|
||||
# @ cdecl _vsnprintf_s(ptr long long str ptr)
|
||||
@ cdecl _vsnprintf_s(ptr long long str ptr)
|
||||
# @ cdecl _vsnprintf_s_l(ptr long long str ptr ptr)
|
||||
@ cdecl _vsnwprintf(ptr long wstr ptr)
|
||||
# @ cdecl _vsnwprintf_l(ptr long wstr ptr ptr)
|
||||
# @ cdecl _vsnwprintf_s(ptr long long wstr ptr)
|
||||
@ cdecl _vsnwprintf_s(ptr long long wstr ptr)
|
||||
# @ cdecl _vsnwprintf_s_l(ptr long long wstr ptr ptr)
|
||||
# stub _vsprintf_l
|
||||
@ cdecl _vsprintf_p(ptr long str ptr)
|
||||
|
@ -1313,7 +1313,7 @@
|
|||
@ cdecl -arch=x86_64 sinf(long)
|
||||
@ cdecl sinh(double)
|
||||
@ varargs sprintf(ptr str)
|
||||
# @ varargs sprintf_s(ptr long str)
|
||||
@ varargs sprintf_s(ptr long str)
|
||||
@ cdecl sqrt(double)
|
||||
@ cdecl -arch=x86_64 sqrtf(long)
|
||||
@ cdecl srand(long)
|
||||
|
@ -1348,7 +1348,7 @@
|
|||
@ cdecl strtoul(str ptr long)
|
||||
@ cdecl strxfrm(ptr str long)
|
||||
@ varargs swprintf(ptr wstr)
|
||||
# @ varargs swprintf_s(ptr long wstr)
|
||||
@ varargs swprintf_s(ptr long wstr)
|
||||
@ varargs swscanf(wstr wstr)
|
||||
# @ varargs swscanf_s(wstr wstr)
|
||||
@ cdecl system(str)
|
||||
|
@ -1374,9 +1374,9 @@
|
|||
@ cdecl vprintf_s(str ptr)
|
||||
# stub vsnprintf
|
||||
@ cdecl vsprintf(ptr str ptr)
|
||||
# @ cdecl vsprintf_s(ptr long str ptr)
|
||||
@ cdecl vsprintf_s(ptr long str ptr)
|
||||
@ cdecl vswprintf(ptr wstr ptr)
|
||||
# @ cdecl vswprintf_s(ptr long wstr ptr)
|
||||
@ cdecl vswprintf_s(ptr long wstr ptr)
|
||||
@ cdecl vwprintf(wstr ptr)
|
||||
@ cdecl vwprintf_s(wstr ptr)
|
||||
# stub wcrtomb
|
||||
|
|
|
@ -135,13 +135,17 @@ list(APPEND CRT_SOURCE
|
|||
printf/_cprintf.c
|
||||
printf/_cwprintf.c
|
||||
printf/_snprintf.c
|
||||
printf/_snprintf_s.c
|
||||
printf/_snwprintf.c
|
||||
printf/_snwprintf_s.c
|
||||
printf/_vcprintf.c
|
||||
printf/_vcwprintf.c
|
||||
printf/_vscprintf.c
|
||||
printf/_vscwprintf.c
|
||||
printf/_vsnprintf.c
|
||||
printf/_vsnprintf_s.c
|
||||
printf/_vsnwprintf.c
|
||||
printf/_vsnwprintf_s.c
|
||||
printf/_vsprintf_p.c
|
||||
printf/fprintf.c
|
||||
printf/fprintf_s.c
|
||||
|
@ -150,8 +154,10 @@ list(APPEND CRT_SOURCE
|
|||
printf/printf.c
|
||||
printf/printf_s.c
|
||||
printf/sprintf.c
|
||||
printf/sprintf_s.c
|
||||
printf/streamout.c
|
||||
printf/swprintf.c
|
||||
printf/swprintf_s.c
|
||||
printf/vfprintf.c
|
||||
printf/vfprintf_s.c
|
||||
printf/vfwprintf.c
|
||||
|
@ -159,7 +165,9 @@ list(APPEND CRT_SOURCE
|
|||
printf/vprintf.c
|
||||
printf/vprintf_s.c
|
||||
printf/vsprintf.c
|
||||
printf/vsprintf_s.c
|
||||
printf/vswprintf.c
|
||||
printf/vswprintf_s.c
|
||||
printf/vwprintf.c
|
||||
printf/vwprintf_s.c
|
||||
printf/wprintf.c
|
||||
|
|
13
reactos/lib/sdk/crt/printf/_snprintf_s.c
Normal file
13
reactos/lib/sdk/crt/printf/_snprintf_s.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||
* PROJECT: ReactOS crt library
|
||||
* FILE: lib/sdk/crt/printf/_snprintf_s.c
|
||||
* PURPOSE: Implementation of _snprintf_s
|
||||
* PROGRAMMER: Timo Kreuzer
|
||||
*/
|
||||
|
||||
#define _sxprintf _snprintf_s
|
||||
#define USE_COUNT 1
|
||||
#define IS_SECAPI 1
|
||||
|
||||
#include "_sxprintf.c"
|
14
reactos/lib/sdk/crt/printf/_snwprintf_s.c
Normal file
14
reactos/lib/sdk/crt/printf/_snwprintf_s.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||
* PROJECT: ReactOS crt library
|
||||
* FILE: lib/sdk/crt/printf/_snwprintf_s.c
|
||||
* PURPOSE: Implementation of _snwprintf_s
|
||||
* PROGRAMMER: Timo Kreuzer
|
||||
*/
|
||||
|
||||
#define _sxprintf _snwprintf_s
|
||||
#define USE_COUNT 1
|
||||
#define _UNICODE
|
||||
#define IS_SECAPI 1
|
||||
|
||||
#include "_sxprintf.c"
|
|
@ -10,6 +10,9 @@
|
|||
#include <stdarg.h>
|
||||
#include <limits.h>
|
||||
#include <tchar.h>
|
||||
#if IS_SECAPI
|
||||
#include <internal/safecrt.h>
|
||||
#endif
|
||||
|
||||
#ifdef _UNICODE
|
||||
#define _tstreamout wstreamout
|
||||
|
@ -17,6 +20,8 @@
|
|||
#define _tstreamout streamout
|
||||
#endif
|
||||
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
int _cdecl _tstreamout(FILE *stream, const TCHAR *format, va_list argptr);
|
||||
|
||||
int
|
||||
|
@ -27,6 +32,9 @@ _cdecl
|
|||
#endif
|
||||
_sxprintf(
|
||||
TCHAR *buffer,
|
||||
#if IS_SECAPI
|
||||
size_t sizeOfBuffer,
|
||||
#endif
|
||||
#if USE_COUNT
|
||||
size_t count,
|
||||
#endif
|
||||
|
@ -37,20 +45,42 @@ _sxprintf(
|
|||
...)
|
||||
#endif
|
||||
{
|
||||
#if !USE_COUNT
|
||||
const size_t count = INT_MAX;
|
||||
#endif
|
||||
#if !IS_SECAPI
|
||||
const size_t sizeOfBuffer = count;
|
||||
#endif
|
||||
#if !USE_VARARGS
|
||||
va_list argptr;
|
||||
#endif
|
||||
int result;
|
||||
FILE stream;
|
||||
|
||||
/* Check trivial case */
|
||||
if ((buffer == NULL) && (count == 0) && (sizeOfBuffer == 0))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if IS_SECAPI
|
||||
/* Validate parameters */
|
||||
if (MSVCRT_CHECK_PMT(((buffer == NULL) || (format == NULL) || (sizeOfBuffer <= 0))))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Limit output to count + 1 characters */
|
||||
if (count != -1)
|
||||
sizeOfBuffer = min(sizeOfBuffer, count + 1);
|
||||
#endif
|
||||
|
||||
/* Setup the FILE structure */
|
||||
stream._base = (char*)buffer;
|
||||
stream._ptr = stream._base;
|
||||
stream._charbuf = 0;
|
||||
#if USE_COUNT
|
||||
stream._cnt = (int)(count * sizeof(TCHAR));
|
||||
#else
|
||||
stream._cnt = INT_MAX;
|
||||
#endif
|
||||
stream._cnt = (int)(sizeOfBuffer * sizeof(TCHAR));
|
||||
stream._bufsiz = 0;
|
||||
stream._flag = _IOSTRG | _IOWRT;
|
||||
stream._tmpfname = 0;
|
||||
|
@ -63,8 +93,33 @@ _sxprintf(
|
|||
va_end(argptr);
|
||||
#endif
|
||||
|
||||
#if IS_SECAPI
|
||||
/* Check for failure or unterminated string */
|
||||
if ((result < 0) || (result == sizeOfBuffer))
|
||||
{
|
||||
/* Null-terminate the buffer at the end */
|
||||
buffer[sizeOfBuffer-1] = _T('\0');
|
||||
|
||||
/* Check if we can truncate */
|
||||
if (count != _TRUNCATE)
|
||||
{
|
||||
/* We can't, invoke invalid parameter handler */
|
||||
MSVCRT_INVALID_PMT("Buffer is too small");
|
||||
|
||||
/* If we came back, set the buffer to an empty string */
|
||||
*buffer = 0;
|
||||
}
|
||||
|
||||
/* Return failure */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Null-terminate the buffer after the string */
|
||||
buffer[result] = _T('\0');
|
||||
#else
|
||||
/* Only zero terminate if there is enough space left */
|
||||
if (stream._cnt >= sizeof(TCHAR)) *(TCHAR*)stream._ptr = _T('\0');
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
14
reactos/lib/sdk/crt/printf/_vsnprintf_s.c
Normal file
14
reactos/lib/sdk/crt/printf/_vsnprintf_s.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||
* PROJECT: ReactOS crt library
|
||||
* FILE: lib/sdk/crt/printf/_vsnprintf_s.c
|
||||
* PURPOSE: Implementation of _vsnprintf_s
|
||||
* PROGRAMMER: Timo Kreuzer
|
||||
*/
|
||||
|
||||
#define _sxprintf _vsnprintf_s
|
||||
#define USE_COUNT 1
|
||||
#define USE_VARARGS 1
|
||||
#define IS_SECAPI 1
|
||||
|
||||
#include "_sxprintf.c"
|
15
reactos/lib/sdk/crt/printf/_vsnwprintf_s.c
Normal file
15
reactos/lib/sdk/crt/printf/_vsnwprintf_s.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||
* PROJECT: ReactOS crt library
|
||||
* FILE: lib/sdk/crt/printf/_vsnwprintf_s.c
|
||||
* PURPOSE: Implementation of _vsnwprintf_s
|
||||
* PROGRAMMER: Timo Kreuzer
|
||||
*/
|
||||
|
||||
#define _sxprintf _vsnwprintf_s
|
||||
#define USE_COUNT 1
|
||||
#define USE_VARARGS 1
|
||||
#define _UNICODE
|
||||
#define IS_SECAPI 1
|
||||
|
||||
#include "_sxprintf.c"
|
13
reactos/lib/sdk/crt/printf/sprintf_s.c
Normal file
13
reactos/lib/sdk/crt/printf/sprintf_s.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||
* PROJECT: ReactOS crt library
|
||||
* FILE: lib/sdk/crt/printf/sprintf_s.c
|
||||
* PURPOSE: Implementation of sprintf_s
|
||||
* PROGRAMMER: Timo Kreuzer
|
||||
*/
|
||||
|
||||
#define _sxprintf sprintf_s
|
||||
#define USE_COUNT 0
|
||||
#define IS_SECAPI 1
|
||||
|
||||
#include "_sxprintf.c"
|
14
reactos/lib/sdk/crt/printf/swprintf_s.c
Normal file
14
reactos/lib/sdk/crt/printf/swprintf_s.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||
* PROJECT: ReactOS crt library
|
||||
* FILE: lib/sdk/crt/printf/swprintf_s.c
|
||||
* PURPOSE: Implementation of swprintf_s
|
||||
* PROGRAMMER: Timo Kreuzer
|
||||
*/
|
||||
|
||||
#define _sxprintf swprintf_s
|
||||
#define USE_COUNT 0
|
||||
#define USE_VARARGS 0
|
||||
#define IS_SECAPI 1
|
||||
|
||||
#include "_sxprintf.c"
|
14
reactos/lib/sdk/crt/printf/vsprintf_s.c
Normal file
14
reactos/lib/sdk/crt/printf/vsprintf_s.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||
* PROJECT: ReactOS crt library
|
||||
* FILE: lib/sdk/crt/printf/vsprintf_s.c
|
||||
* PURPOSE: Implementation of vsprintf_s
|
||||
* PROGRAMMER: Timo Kreuzer
|
||||
*/
|
||||
|
||||
#define _sxprintf vsprintf_s
|
||||
#define USE_COUNT 0
|
||||
#define USE_VARARGS 1
|
||||
#define IS_SECAPI 1
|
||||
|
||||
#include "_sxprintf.c"
|
15
reactos/lib/sdk/crt/printf/vswprintf_s.c
Normal file
15
reactos/lib/sdk/crt/printf/vswprintf_s.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||
* PROJECT: ReactOS crt library
|
||||
* FILE: lib/sdk/crt/printf/vswprintf_s.c
|
||||
* PURPOSE: Implementation of vswprintf_s
|
||||
* PROGRAMMER: Timo Kreuzer
|
||||
*/
|
||||
|
||||
#define _sxprintf vswprintf_s
|
||||
#define USE_COUNT 0
|
||||
#define USE_VARARGS 1
|
||||
#define _UNICODE
|
||||
#define IS_SECAPI 1
|
||||
|
||||
#include "_sxprintf.c"
|
Loading…
Reference in a new issue