On Monday 25 March 2024 13:59:49 LIU Hao wrote:
> 在 2024-03-24 23:17, Pali Rohár 写道:
> > I see... The problem is that inline version of that function in stdio.h
> > conflicts with non-inline version in ucrt__scprintf.c file.
> > 
> > One option how to avoid this problem is to not include stdio.h into
> > ucrt__scprintf.c file.
> > 
> > Other option can be to remove inline version completely.
> 
> Please propose an updated patch for that.
> 
> In 'ucrt__snwprintf.c' there are some hacks around it.

Thank you for help. In attachment is an updated version. I checked that
it works on top of the current master branch (because original version
of the change is 2 years old now) and that it works for cases when
target application includes stdio.h header file and also when it does
not include it.
>From f2ab09dab3bff2ab4e76c93fd448fce9b28ec4c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.ro...@gmail.com>
Date: Sun, 6 Feb 2022 20:15:41 +0100
Subject: [PATCH v2] crt: Add non-inline variant of UCRT _scprintf, _snprintf
 and _snscanf functions

---
 mingw-w64-crt/Makefile.am            |  3 +++
 mingw-w64-crt/stdio/ucrt__scprintf.c | 23 +++++++++++++++++++++++
 mingw-w64-crt/stdio/ucrt__snprintf.c | 23 +++++++++++++++++++++++
 mingw-w64-crt/stdio/ucrt__snscanf.c  | 23 +++++++++++++++++++++++
 4 files changed, 72 insertions(+)
 create mode 100644 mingw-w64-crt/stdio/ucrt__scprintf.c
 create mode 100644 mingw-w64-crt/stdio/ucrt__snprintf.c
 create mode 100644 mingw-w64-crt/stdio/ucrt__snscanf.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index bf3628e4cf67..a70b270c4cb6 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -356,6 +356,9 @@ src_ucrtbase=\
   stdio/ucrt_fwprintf.c \
   stdio/ucrt_printf.c \
   stdio/ucrt_scanf.c \
+  stdio/ucrt__scprintf.c \
+  stdio/ucrt__snprintf.c \
+  stdio/ucrt__snscanf.c \
   stdio/ucrt__snwprintf.c \
   stdio/ucrt_snprintf.c \
   stdio/ucrt_sprintf.c \
diff --git a/mingw-w64-crt/stdio/ucrt__scprintf.c b/mingw-w64-crt/stdio/ucrt__scprintf.c
new file mode 100644
index 000000000000..285d32017474
--- /dev/null
+++ b/mingw-w64-crt/stdio/ucrt__scprintf.c
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+
+#undef __MSVCRT_VERSION__
+#define _UCRT
+#define _scprintf real__scprintf
+#include <stdio.h>
+#include <stdarg.h>
+#undef _scprintf
+
+int __cdecl _scprintf(const char * __restrict__ _Format, ...)
+{
+  int ret;
+  va_list _ArgList;
+  va_start(_ArgList, _Format);
+  ret = __stdio_common_vsprintf(_CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR, NULL, 0, _Format, NULL, _ArgList);
+  va_end(_ArgList);
+  return ret;
+}
+int __cdecl (*__MINGW_IMP_SYMBOL(_scprintf))(const char *__restrict__, ...) = _scprintf;
diff --git a/mingw-w64-crt/stdio/ucrt__snprintf.c b/mingw-w64-crt/stdio/ucrt__snprintf.c
new file mode 100644
index 000000000000..9a43846f362a
--- /dev/null
+++ b/mingw-w64-crt/stdio/ucrt__snprintf.c
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+
+#undef __MSVCRT_VERSION__
+#define _UCRT
+#define _snprintf real__snprintf
+#include <stdio.h>
+#include <stdarg.h>
+#undef _snprintf
+
+int __cdecl _snprintf(char * __restrict__ _Dest, size_t _Count, const char * __restrict__ _Format, ...)
+{
+  int ret;
+  va_list _Args;
+  va_start(_Args, _Format);
+  ret = __stdio_common_vsprintf(_CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, _Dest, _Count, _Format, NULL, _Args);
+  va_end(_Args);
+  return ret;
+}
+int __cdecl (*__MINGW_IMP_SYMBOL(_snprintf))(char *__restrict__, size_t, const char *__restrict__, ...) = _snprintf;
diff --git a/mingw-w64-crt/stdio/ucrt__snscanf.c b/mingw-w64-crt/stdio/ucrt__snscanf.c
new file mode 100644
index 000000000000..43c64efadaf8
--- /dev/null
+++ b/mingw-w64-crt/stdio/ucrt__snscanf.c
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+
+#undef __MSVCRT_VERSION__
+#define _UCRT
+#define _snscanf real__snscanf
+#include <stdio.h>
+#include <stdarg.h>
+#undef _snscanf
+
+int __cdecl _snscanf(const char * __restrict__ _Src, size_t _MaxCount, const char * __restrict__ _Format, ...)
+{
+  int ret;
+  va_list _ArgList;
+  va_start(_ArgList, _Format);
+  ret = __stdio_common_vsscanf(0, _Src, _MaxCount, _Format, NULL, _ArgList);
+  va_end(_ArgList);
+  return ret;
+}
+int __cdecl (*__MINGW_IMP_SYMBOL(_snscanf))(const char *__restrict__, size_t, const char * __restrict__, ...) = _snscanf;
-- 
2.20.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