This avoids duplicate definitions, if something refers to e.g.
__ms_vsnprintf, while the inline vsnprintf also has been instantiated
in C++ mode. (In C++ mode, the inline vsnprintf function isn't marked
static.)

This should fix https://github.com/msys2/MINGW-packages/issues/6271.

Signed-off-by: Martin Storsjö <[email protected]>
---
 mingw-w64-crt/Makefile.am                  |  2 ++
 mingw-w64-crt/stdio/snprintf.c             | 15 +------------
 mingw-w64-crt/stdio/snprintf_unprefixed.c  | 25 ++++++++++++++++++++++
 mingw-w64-crt/stdio/vsnprintf.c            | 14 +-----------
 mingw-w64-crt/stdio/vsnprintf_unprefixed.c | 19 ++++++++++++++++
 5 files changed, 48 insertions(+), 27 deletions(-)
 create mode 100644 mingw-w64-crt/stdio/snprintf_unprefixed.c
 create mode 100644 mingw-w64-crt/stdio/vsnprintf_unprefixed.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 87bf70176..6241b1b7c 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -170,7 +170,9 @@ src_msvcrt_common=\
   misc/wcrtomb.c \
   stdio/acrt_iob_func.c \
   stdio/snprintf.c \
+  stdio/snprintf_unprefixed.c \
   stdio/vsnprintf.c \
+  stdio/vsnprintf_unprefixed.c \
   math/frexp.c
 
 src_msvcrt=\
diff --git a/mingw-w64-crt/stdio/snprintf.c b/mingw-w64-crt/stdio/snprintf.c
index ad9dd5678..0bb5556fe 100644
--- a/mingw-w64-crt/stdio/snprintf.c
+++ b/mingw-w64-crt/stdio/snprintf.c
@@ -3,19 +3,8 @@
  * 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 <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, ...);
+#include <stdio.h>
 
 int __cdecl __ms_snprintf(char* buffer, size_t n, const char *format, ...)
 {
@@ -47,5 +36,3 @@ 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/snprintf_unprefixed.c 
b/mingw-w64-crt/stdio/snprintf_unprefixed.c
new file mode 100644
index 000000000..1c34114d3
--- /dev/null
+++ b/mingw-w64-crt/stdio/snprintf_unprefixed.c
@@ -0,0 +1,25 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <stdarg.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". */
+
+int __cdecl __ms_vsnprintf(char *buffer, size_t n, const char *format, va_list 
arg);
+
+int __cdecl snprintf(char *buffer, size_t n, const char *format, ...)
+{
+  int retval;
+  va_list argptr;
+
+  va_start(argptr, format);
+  retval = __ms_vsnprintf(buffer, n, format, argptr);
+  va_end(argptr);
+  return retval;
+}
diff --git a/mingw-w64-crt/stdio/vsnprintf.c b/mingw-w64-crt/stdio/vsnprintf.c
index 9c4f83b96..364186702 100644
--- a/mingw-w64-crt/stdio/vsnprintf.c
+++ b/mingw-w64-crt/stdio/vsnprintf.c
@@ -4,18 +4,8 @@
  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  */
 #define __CRT__NO_INLINE
-#include <_mingw.h>
 #include <stdarg.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);
+#include <stdio.h>
 
 int __cdecl __ms_vsnprintf (char *s,size_t n,const char *format,va_list arg)
 {
@@ -39,5 +29,3 @@ 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);
diff --git a/mingw-w64-crt/stdio/vsnprintf_unprefixed.c 
b/mingw-w64-crt/stdio/vsnprintf_unprefixed.c
new file mode 100644
index 000000000..8c7c9b930
--- /dev/null
+++ b/mingw-w64-crt/stdio/vsnprintf_unprefixed.c
@@ -0,0 +1,19 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <stdarg.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". */
+
+int __cdecl __ms_vsnprintf(char *buffer, size_t n, const char *format, va_list 
arg);
+
+int __cdecl vsnprintf(char *buffer, size_t n, const char *format, va_list arg)
+{
+  return __ms_vsnprintf(buffer, n, format, arg);
+}
-- 
2.17.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to