[PATCH 2/5] msvcrt: Implement vfprintf_s and vfwprintf_s.
Eryk Wieliczko
ewdevel at gmail.com
Wed Nov 24 14:12:35 CST 2010
---
dlls/msvcr100/msvcr100.spec | 4 +-
dlls/msvcr80/msvcr80.spec | 4 +-
dlls/msvcr90/msvcr90.spec | 4 +-
dlls/msvcrt/file.c | 72 +++++++++++++++++++++++++++++++++++++++++++
dlls/msvcrt/msvcrt.spec | 4 +-
include/msvcrt/stdio.h | 2 +
include/msvcrt/wchar.h | 1 +
7 files changed, 83 insertions(+), 8 deletions(-)
diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec
index 8e71b31..16854b4 100644
--- a/dlls/msvcr100/msvcr100.spec
+++ b/dlls/msvcr100/msvcr100.spec
@@ -1617,9 +1617,9 @@
@ cdecl ungetc(long ptr) msvcrt.ungetc
@ cdecl ungetwc(long ptr) msvcrt.ungetwc
@ cdecl vfprintf(ptr str ptr) msvcrt.vfprintf
-@ stub vfprintf_s
+@ cdecl vfprintf_s(ptr str ptr) msvcrt.vfprintf_s
@ cdecl vfwprintf(ptr wstr ptr) msvcrt.vfwprintf
-@ stub vfwprintf_s
+@ cdecl vfwprintf_s(ptr wstr ptr) msvcrt.vfwprintf_s
@ cdecl vprintf(str ptr) msvcrt.vprintf
@ stub vprintf_s
@ cdecl vsprintf(ptr str ptr) msvcrt.vsprintf
diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec
index 5e52a28..3bee113 100644
--- a/dlls/msvcr80/msvcr80.spec
+++ b/dlls/msvcr80/msvcr80.spec
@@ -1471,9 +1471,9 @@
@ cdecl ungetc(long ptr) msvcrt.ungetc
@ cdecl ungetwc(long ptr) msvcrt.ungetwc
@ cdecl vfprintf(ptr str ptr) msvcrt.vfprintf
-@ stub vfprintf_s
+@ cdecl vfprintf_s(ptr str ptr) msvcrt.vfprintf_s
@ cdecl vfwprintf(ptr wstr ptr) msvcrt.vfwprintf
-@ stub vfwprintf_s
+@ cdecl vfwprintf_s(ptr wstr ptr) msvcrt.vfwprintf_s
@ cdecl vprintf(str ptr) msvcrt.vprintf
@ stub vprintf_s
@ cdecl vsprintf(ptr str ptr) msvcrt.vsprintf
diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec
index 6b2d664..536db47 100644
--- a/dlls/msvcr90/msvcr90.spec
+++ b/dlls/msvcr90/msvcr90.spec
@@ -1455,9 +1455,9 @@
@ cdecl ungetc(long ptr) msvcrt.ungetc
@ cdecl ungetwc(long ptr) msvcrt.ungetwc
@ cdecl vfprintf(ptr str ptr) msvcrt.vfprintf
-@ stub vfprintf_s
+@ cdecl vfprintf_s(ptr str ptr) msvcrt.vfprintf_s
@ cdecl vfwprintf(ptr wstr ptr) msvcrt.vfwprintf
-@ stub vfwprintf_s
+@ cdecl vfwprintf_s(ptr wstr ptr) msvcrt.vfwprintf_s
@ cdecl vprintf(str ptr) msvcrt.vprintf
@ stub vprintf_s
@ cdecl vsprintf(ptr str ptr) msvcrt.vsprintf
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index ae4a215..809cdda 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -3368,6 +3368,45 @@ int CDECL MSVCRT_vfprintf(MSVCRT_FILE* file, const char *format, __ms_va_list va
}
/*********************************************************************
+ * vfprintf_s (MSVCRT.@)
+ */
+int CDECL MSVCRT_vfprintf_s(MSVCRT_FILE* file, const char *format, __ms_va_list valist)
+{
+ char buf[2048];
+ LPWSTR formatW = NULL;
+ DWORD sz;
+ pf_output out;
+ int written, retval;
+
+ if( !MSVCRT_CHECK_PMT( file != NULL ) )
+ {
+ *MSVCRT__errno() = MSVCRT_EINVAL;
+ return -1;
+ }
+
+ out.unicode = FALSE;
+ out.buf.A = out.grow.A = buf;
+ out.used = 0;
+ out.len = sizeof(buf);
+
+ sz = MultiByteToWideChar( CP_ACP, 0, format, -1, NULL, 0 );
+ formatW = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) );
+ MultiByteToWideChar( CP_ACP, 0, format, -1, formatW, sz );
+
+ if ((written = pf_vsnprintf( &out, formatW, NULL, TRUE, valist )) >= 0)
+ {
+ retval = MSVCRT_fwrite(out.buf.A, sizeof(*out.buf.A), written, file);
+ }
+ else retval = -1;
+
+ HeapFree( GetProcessHeap(), 0, formatW );
+
+ if (out.buf.A != out.grow.A)
+ MSVCRT_free (out.buf.A);
+ return retval;
+}
+
+/*********************************************************************
* vfwprintf (MSVCRT.@)
* FIXME:
* Is final char included in written (then resize is too big) or not
@@ -3401,6 +3440,39 @@ int CDECL MSVCRT_vfwprintf(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, __ms
}
/*********************************************************************
+ * vfwprintf_s (MSVCRT.@)
+ * FIXME:
+ * Is final char included in written (then resize is too big) or not
+ * (then we must test for equality too)?
+ */
+int CDECL MSVCRT_vfwprintf_s(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, __ms_va_list valist)
+{
+ MSVCRT_wchar_t buf[2048];
+ pf_output out;
+ int written, retval;
+
+ if( !MSVCRT_CHECK_PMT( file != NULL ) )
+ {
+ *MSVCRT__errno() = MSVCRT_EINVAL;
+ return -1;
+ }
+
+ out.unicode = TRUE;
+ out.buf.W = out.grow.W = buf;
+ out.used = 0;
+ out.len = sizeof(buf) / sizeof(buf[0]);
+
+ if ((written = pf_vsnprintf( &out, format, NULL, TRUE, valist )) >= 0)
+ {
+ retval = MSVCRT_fwrite(out.buf.W, sizeof(*out.buf.W), written, file);
+ }
+ else retval = -1;
+ if (out.buf.W != out.grow.W)
+ MSVCRT_free (out.buf.W);
+ return retval;
+}
+
+/*********************************************************************
* vprintf (MSVCRT.@)
*/
int CDECL MSVCRT_vprintf(const char *format, __ms_va_list valist)
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 11d0a49..b6d1f10 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -1422,9 +1422,9 @@
@ cdecl ungetwc(long ptr) MSVCRT_ungetwc
# stub utime
@ cdecl vfprintf(ptr str ptr) MSVCRT_vfprintf
-# stub vfprintf_s
+@ cdecl vfprintf_s(ptr str ptr) MSVCRT_vfprintf_s
@ cdecl vfwprintf(ptr wstr ptr) MSVCRT_vfwprintf
-# stub vfwprintf_s
+@ cdecl vfwprintf_s(ptr wstr ptr) MSVCRT_vfwprintf_s
@ cdecl vprintf(str ptr) MSVCRT_vprintf
# stub vprintf_s
# stub vsnprintf
diff --git a/include/msvcrt/stdio.h b/include/msvcrt/stdio.h
index a190f5d..e27c8ca 100644
--- a/include/msvcrt/stdio.h
+++ b/include/msvcrt/stdio.h
@@ -166,6 +166,7 @@ FILE* __cdecl tmpfile(void);
char* __cdecl tmpnam(char*);
int __cdecl ungetc(int,FILE*);
int __cdecl vfprintf(FILE*,const char*,__ms_va_list);
+int __cdecl vfprintf_s(FILE*,const char*,__ms_va_list);
int __cdecl vprintf(const char*,__ms_va_list);
int __cdecl vsprintf(char*,const char*,__ms_va_list);
int __cdecl vsprintf_s(char*,size_t,const char*,__ms_va_list);
@@ -212,6 +213,7 @@ int __cdecl swscanf(const wchar_t*,const wchar_t*,...);
int __cdecl swscanf_s(const wchar_t*,const wchar_t*,...);
wint_t __cdecl ungetwc(wint_t,FILE*);
int __cdecl vfwprintf(FILE*,const wchar_t*,__ms_va_list);
+int __cdecl vfwprintf_s(FILE*,const wchar_t*,__ms_va_list);
int __cdecl vswprintf(wchar_t*,const wchar_t*,__ms_va_list);
int __cdecl vswprintf_s(wchar_t*,size_t,const wchar_t*,__ms_va_list);
int __cdecl vwprintf(const wchar_t*,__ms_va_list);
diff --git a/include/msvcrt/wchar.h b/include/msvcrt/wchar.h
index c5ab25f..7c495f0 100644
--- a/include/msvcrt/wchar.h
+++ b/include/msvcrt/wchar.h
@@ -310,6 +310,7 @@ int __cdecl swscanf(const wchar_t*,const wchar_t*,...);
int __cdecl swscanf_s(const wchar_t*,const wchar_t*,...);
wint_t __cdecl ungetwc(wint_t,FILE*);
int __cdecl vfwprintf(FILE*,const wchar_t*,__ms_va_list);
+int __cdecl vfwprintf_s(FILE*,const wchar_t*,__ms_va_list);
int __cdecl vswprintf(wchar_t*,const wchar_t*,__ms_va_list);
int __cdecl vswprintf_s(wchar_t*,size_t,const wchar_t*,__ms_va_list);
int __cdecl vwprintf(const wchar_t*,__ms_va_list);
--
1.7.0.4
More information about the wine-patches
mailing list