Author: tkreuzer
Date: Sat Mar 16 13:40:28 2013
New Revision: 58515
URL:
http://svn.reactos.org/svn/reactos?rev=58515&view=rev
Log:
[CRT]
Implement [v]s[nw]printf_s
[MSVCRT]
Enable [v]s[nw]printf_s exports
Added:
trunk/reactos/lib/sdk/crt/printf/_snprintf_s.c (with props)
trunk/reactos/lib/sdk/crt/printf/_snwprintf_s.c (with props)
trunk/reactos/lib/sdk/crt/printf/_vsnprintf_s.c (with props)
trunk/reactos/lib/sdk/crt/printf/_vsnwprintf_s.c (with props)
trunk/reactos/lib/sdk/crt/printf/sprintf_s.c (with props)
trunk/reactos/lib/sdk/crt/printf/swprintf_s.c (with props)
trunk/reactos/lib/sdk/crt/printf/vsprintf_s.c (with props)
trunk/reactos/lib/sdk/crt/printf/vswprintf_s.c (with props)
Modified:
trunk/reactos/dll/win32/msvcrt/msvcrt.spec
trunk/reactos/lib/sdk/crt/crt.cmake
trunk/reactos/lib/sdk/crt/printf/_sxprintf.c
Modified: trunk/reactos/dll/win32/msvcrt/msvcrt.spec
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msvcrt/msvcrt.sp…
==============================================================================
--- trunk/reactos/dll/win32/msvcrt/msvcrt.spec [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msvcrt/msvcrt.spec [iso-8859-1] Sat Mar 16 13:40:28 2013
@@ -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
Modified: trunk/reactos/lib/sdk/crt/crt.cmake
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/crt.cmake?rev=…
==============================================================================
--- trunk/reactos/lib/sdk/crt/crt.cmake [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/crt.cmake [iso-8859-1] Sat Mar 16 13:40:28 2013
@@ -135,13 +135,17 @@
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 @@
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 @@
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
Added: trunk/reactos/lib/sdk/crt/printf/_snprintf_s.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_snprin…
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/_snprintf_s.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/_snprintf_s.c [iso-8859-1] Sat Mar 16 13:40:28 2013
@@ -1,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"
Propchange: trunk/reactos/lib/sdk/crt/printf/_snprintf_s.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/lib/sdk/crt/printf/_snwprintf_s.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_snwpri…
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/_snwprintf_s.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/_snwprintf_s.c [iso-8859-1] Sat Mar 16 13:40:28 2013
@@ -1,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"
Propchange: trunk/reactos/lib/sdk/crt/printf/_snwprintf_s.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/lib/sdk/crt/printf/_sxprintf.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_sxprin…
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/_sxprintf.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/printf/_sxprintf.c [iso-8859-1] Sat Mar 16 13:40:28 2013
@@ -10,12 +10,17 @@
#include <stdarg.h>
#include <limits.h>
#include <tchar.h>
+#if IS_SECAPI
+#include <internal/safecrt.h>
+#endif
#ifdef _UNICODE
#define _tstreamout wstreamout
#else
#define _tstreamout streamout
#endif
+
+#define min(a,b) (((a) < (b)) ? (a) : (b))
int _cdecl _tstreamout(FILE *stream, const TCHAR *format, va_list argptr);
@@ -27,6 +32,9 @@
#endif
_sxprintf(
TCHAR *buffer,
+#if IS_SECAPI
+ size_t sizeOfBuffer,
+#endif
#if USE_COUNT
size_t count,
#endif
@@ -37,20 +45,42 @@
...)
#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 @@
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;
}
Added: trunk/reactos/lib/sdk/crt/printf/_vsnprintf_s.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_vsnpri…
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/_vsnprintf_s.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/_vsnprintf_s.c [iso-8859-1] Sat Mar 16 13:40:28 2013
@@ -1,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"
Propchange: trunk/reactos/lib/sdk/crt/printf/_vsnprintf_s.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/lib/sdk/crt/printf/_vsnwprintf_s.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/_vsnwpr…
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/_vsnwprintf_s.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/_vsnwprintf_s.c [iso-8859-1] Sat Mar 16 13:40:28
2013
@@ -1,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"
Propchange: trunk/reactos/lib/sdk/crt/printf/_vsnwprintf_s.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/lib/sdk/crt/printf/sprintf_s.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/sprintf…
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/sprintf_s.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/sprintf_s.c [iso-8859-1] Sat Mar 16 13:40:28 2013
@@ -1,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"
Propchange: trunk/reactos/lib/sdk/crt/printf/sprintf_s.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/lib/sdk/crt/printf/swprintf_s.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/swprint…
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/swprintf_s.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/swprintf_s.c [iso-8859-1] Sat Mar 16 13:40:28 2013
@@ -1,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"
Propchange: trunk/reactos/lib/sdk/crt/printf/swprintf_s.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/lib/sdk/crt/printf/vsprintf_s.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/vsprint…
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/vsprintf_s.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/vsprintf_s.c [iso-8859-1] Sat Mar 16 13:40:28 2013
@@ -1,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"
Propchange: trunk/reactos/lib/sdk/crt/printf/vsprintf_s.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/lib/sdk/crt/printf/vswprintf_s.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/vswprin…
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/vswprintf_s.c (added)
+++ trunk/reactos/lib/sdk/crt/printf/vswprintf_s.c [iso-8859-1] Sat Mar 16 13:40:28 2013
@@ -1,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"
Propchange: trunk/reactos/lib/sdk/crt/printf/vswprintf_s.c
------------------------------------------------------------------------------
svn:eol-style = native