Prior to dc3b2e2bfa9b5a4fcee6f0123047ecc5a6a35d1f, snprintf was
aliased to _snprintf and vsnprintf was aliased to _vsnprintf in
the import library. As _snprintf doesn't really behave as snprintf
should, the aliases were removed.

Instead make them aliases to the __ms_snprintf and __ms_vsnprintf
functions, which is what one would end up linking against when
referencing snprintf/vsnprintf after including stdio.h, unless
__USE_MINGW_ANSI_STDIO is defined.

This is necessary, as the snprintf function needs to exist with
that symbol name, as certain projects/build systems try to detect its
presence with a linking test, without including stdio.h.

Signed-off-by: Martin Storsjö <mar...@martin.st>
---
 mingw-w64-crt/stdio/snprintf.c  | 15 ++++++++++++++-
 mingw-w64-crt/stdio/vsnprintf.c | 14 +++++++++++++-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/mingw-w64-crt/stdio/snprintf.c b/mingw-w64-crt/stdio/snprintf.c
index 0bb5556fe..ad9dd5678 100644
--- a/mingw-w64-crt/stdio/snprintf.c
+++ b/mingw-w64-crt/stdio/snprintf.c
@@ -3,8 +3,19 @@
  * This file is part of the mingw-w64 runtime package.
  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  */
+
+#include <_mingw.h>
 #include <stdarg.h>
-#include <stdio.h>
+#include <stddef.h>
+
+/* Intentionally not including stdio.h, as it unconditionally defines the
+ * snprintf inline, and it can't be renamed with "#define snprintf othername"
+ * either, as stdio.h contains "#undef snprintf". */
+
+_CRTIMP int __cdecl _vscprintf(const char * __restrict__ _Format,va_list 
_ArgList);
+_CRTIMP int __cdecl _vsnprintf(char * __restrict__ _Dest,size_t _Count,const 
char * __restrict__ _Format,va_list _Args);
+
+int __cdecl __ms_snprintf(char* buffer, size_t n, const char *format, ...);
 
 int __cdecl __ms_snprintf(char* buffer, size_t n, const char *format, ...)
 {
@@ -36,3 +47,5 @@ int __cdecl __ms_snprintf(char* buffer, size_t n, const char 
*format, ...)
   va_end(argptr);
   return retval;
 }
+
+int __attribute__ ((alias ("__ms_snprintf"))) __cdecl snprintf(char*, size_t, 
const char *, ...);
diff --git a/mingw-w64-crt/stdio/vsnprintf.c b/mingw-w64-crt/stdio/vsnprintf.c
index 364186702..9c4f83b96 100644
--- a/mingw-w64-crt/stdio/vsnprintf.c
+++ b/mingw-w64-crt/stdio/vsnprintf.c
@@ -4,8 +4,18 @@
  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  */
 #define __CRT__NO_INLINE
+#include <_mingw.h>
 #include <stdarg.h>
-#include <stdio.h>
+#include <stddef.h>
+
+/* Intentionally not including stdio.h, as it unconditionally defines the
+ * vsnprintf inline, and it can't be renamed with "#define vsnprintf othername"
+ * either, as stdio.h contains "#undef vsnprintf". */
+
+_CRTIMP int __cdecl _vscprintf(const char * __restrict__ _Format,va_list 
_ArgList);
+_CRTIMP int __cdecl _vsnprintf(char * __restrict__ _Dest,size_t _Count,const 
char * __restrict__ _Format,va_list _Args);
+
+int __cdecl __ms_vsnprintf (char *s,size_t n,const char *format,va_list arg);
 
 int __cdecl __ms_vsnprintf (char *s,size_t n,const char *format,va_list arg)
 {
@@ -29,3 +39,5 @@ int __cdecl __ms_vsnprintf (char *s,size_t n,const char 
*format,va_list arg)
 
     return retval;
 }
+
+int __attribute__ ((alias ("__ms_vsnprintf"))) __cdecl vsnprintf(char*, 
size_t, const char *, va_list);
-- 
2.17.1



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to