0002-migrate-percent-m-implementation-1.patch
text/x-diff
Filename: 0002-migrate-percent-m-implementation-1.patch
Type: text/x-diff
Part: 1
Patch
Format: unified
Series: patch 0002
| File | + | − |
|---|---|---|
| config/c-compiler.m4 | 0 | 0 |
| config/c-library.m4 | 0 | 0 |
| configure | 0 | 0 |
| configure.in | 0 | 0 |
| src/backend/lib/stringinfo.c | 0 | 0 |
| src/backend/utils/error/elog.c | 0 | 0 |
| src/bin/pg_dump/pg_backup_archiver.c | 0 | 0 |
| src/bin/pg_dump/pg_backup_tar.c | 0 | 0 |
| src/common/psprintf.c | 0 | 0 |
| src/include/c.h | 0 | 0 |
| src/include/pg_config.h.in | 0 | 0 |
| src/include/pg_config.h.win32 | 0 | 0 |
| src/include/port.h | 0 | 0 |
| src/interfaces/ecpg/compatlib/Makefile | 0 | 0 |
| src/interfaces/ecpg/ecpglib/Makefile | 0 | 0 |
| src/interfaces/ecpg/pgtypeslib/Makefile | 0 | 0 |
| src/interfaces/libpq/Makefile | 0 | 0 |
| src/interfaces/libpq/pqexpbuffer.c | 0 | 0 |
| src/pl/plperl/plperl.h | 0 | 0 |
| src/pl/plpython/plpy_elog.c | 0 | 0 |
| src/pl/plpython/plpython.h | 0 | 0 |
| src/port/Makefile | 0 | 0 |
| src/port/README | 0 | 0 |
| src/port/snprintf.c | 0 | 0 |
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index 67675a3..80e4f8c 100644
*** a/config/c-compiler.m4
--- b/config/c-compiler.m4
*************** fi])# PGAC_C_SIGNED
*** 20,34 ****
# PGAC_C_PRINTF_ARCHETYPE
# -----------------------
# Select the format archetype to be used by gcc to check printf-type functions.
! # We prefer "gnu_printf", which matches the features glibc supports, notably
! # %m, 'z' and 'll' width modifiers ('ll' only matters if int64 requires it),
! # and argument order control if we're doing --enable-nls. On platforms where
! # the native printf doesn't have 'z'/'ll' or arg control, we replace it with
! # src/port/snprintf.c which does, so that the only potential mismatch here is
! # whether or not %m is supported. We need that for elog/ereport, so we live
! # with the fact that erroneous use of %m in plain printf calls won't be
! # detected. (It appears that many versions of gcc/clang wouldn't report it
! # even if told to check according to plain printf archetype, anyway.)
AC_DEFUN([PGAC_PRINTF_ARCHETYPE],
[AC_CACHE_CHECK([for printf format archetype], pgac_cv_printf_archetype,
[ac_save_c_werror_flag=$ac_c_werror_flag
--- 20,27 ----
# PGAC_C_PRINTF_ARCHETYPE
# -----------------------
# Select the format archetype to be used by gcc to check printf-type functions.
! # We prefer "gnu_printf", as that most closely matches the features supported
! # by src/port/snprintf.c (particularly the %m conversion spec).
AC_DEFUN([PGAC_PRINTF_ARCHETYPE],
[AC_CACHE_CHECK([for printf format archetype], pgac_cv_printf_archetype,
[ac_save_c_werror_flag=$ac_c_werror_flag
diff --git a/config/c-library.m4 b/config/c-library.m4
index da7fa77..d371f1b 100644
*** a/config/c-library.m4
--- b/config/c-library.m4
*************** AC_DEFUN([PGAC_STRUCT_ADDRINFO],
*** 171,276 ****
])])# PGAC_STRUCT_ADDRINFO
- # PGAC_FUNC_SNPRINTF_ARG_CONTROL
- # ---------------------------------------
- # Determine if snprintf supports %1$ argument selection, e.g. %5$ selects
- # the fifth argument after the printf format string.
- # This is not in the C99 standard, but in the Single Unix Specification (SUS).
- # It is used in our language translation strings.
- #
- AC_DEFUN([PGAC_FUNC_SNPRINTF_ARG_CONTROL],
- [AC_MSG_CHECKING([whether snprintf supports argument control])
- AC_CACHE_VAL(pgac_cv_snprintf_arg_control,
- [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
- #include <string.h>
-
- int main()
- {
- char buf[100];
-
- /* can it swap arguments? */
- snprintf(buf, 100, "%2\$d %1\$d", 3, 4);
- if (strcmp(buf, "4 3") != 0)
- return 1;
- return 0;
- }]])],
- [pgac_cv_snprintf_arg_control=yes],
- [pgac_cv_snprintf_arg_control=no],
- [pgac_cv_snprintf_arg_control=cross])
- ])dnl AC_CACHE_VAL
- AC_MSG_RESULT([$pgac_cv_snprintf_arg_control])
- ])# PGAC_FUNC_SNPRINTF_ARG_CONTROL
-
- # PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
- # ---------------------------------
- # Determine if snprintf supports the z length modifier for printing
- # size_t-sized variables. That's supported by C99 and POSIX but not
- # all platforms play ball, so we must test whether it's working.
- #
- AC_DEFUN([PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT],
- [AC_MSG_CHECKING([whether snprintf supports the %z modifier])
- AC_CACHE_VAL(pgac_cv_snprintf_size_t_support,
- [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
- #include <string.h>
-
- int main()
- {
- char bufz[100];
- char buf64[100];
-
- /*
- * Print the largest unsigned number fitting in a size_t using both %zu
- * and the previously-determined format for 64-bit integers. Note that
- * we don't run this code unless we know snprintf handles 64-bit ints.
- */
- bufz[0] = '\0'; /* in case snprintf fails to emit anything */
- snprintf(bufz, sizeof(bufz), "%zu", ~((size_t) 0));
- snprintf(buf64, sizeof(buf64), "%" INT64_MODIFIER "u",
- (unsigned PG_INT64_TYPE) ~((size_t) 0));
- if (strcmp(bufz, buf64) != 0)
- return 1;
- return 0;
- }]])],
- [pgac_cv_snprintf_size_t_support=yes],
- [pgac_cv_snprintf_size_t_support=no],
- [pgac_cv_snprintf_size_t_support=cross])
- ])dnl AC_CACHE_VAL
- AC_MSG_RESULT([$pgac_cv_snprintf_size_t_support])
- ])# PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
-
- # PGAC_FUNC_SNPRINTF_C99_RESULT
- # -----------------------------
- # Determine whether snprintf returns the desired buffer length when
- # it overruns the actual buffer length. That's required by C99 and POSIX
- # but ancient platforms don't behave that way, so we must test.
- # While we're at it, let's just verify that it doesn't physically overrun
- # the buffer.
- #
- AC_DEFUN([PGAC_FUNC_SNPRINTF_C99_RESULT],
- [AC_MSG_CHECKING([whether snprintf handles buffer overrun per C99])
- AC_CACHE_VAL(pgac_cv_snprintf_c99_result,
- [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
- #include <string.h>
-
- int main()
- {
- char buf[10];
-
- strcpy(buf, "abcdefghi");
- if (snprintf(buf, 4, "%d", 123456) != 6)
- return 1;
- if (strcmp(buf, "123") != 0 || buf[4] != 'e')
- return 1;
- return 0;
- }]])],
- [pgac_cv_snprintf_c99_result=yes],
- [pgac_cv_snprintf_c99_result=no],
- [pgac_cv_snprintf_c99_result=cross])
- ])dnl AC_CACHE_VAL
- AC_MSG_RESULT([$pgac_cv_snprintf_c99_result])
- ])# PGAC_FUNC_SNPRINTF_C99_RESULT
-
-
# PGAC_TYPE_LOCALE_T
# ------------------
# Check for the locale_t type and find the right header file. macOS
--- 171,176 ----
diff --git a/configure b/configure
index fadd06e..58f223f 100755
*** a/configure
--- b/configure
*************** $as_echo "#define HAVE_PS_STRINGS 1" >>c
*** 15273,15369 ****
fi
- # We use our snprintf.c emulation if either snprintf() or vsnprintf()
- # is missing. Yes, there are machines that have only one. We may
- # also decide to use snprintf.c if snprintf() is present but does not
- # have all the features we need --- see below.
-
- if test "$PORTNAME" = "win32"; then
- # Win32 gets snprintf.c built unconditionally.
- #
- # To properly translate all NLS languages strings, we must support the
- # *printf() %$ format, which allows *printf() arguments to be selected
- # by position in the translated string.
- #
- # libintl versions < 0.13 use the native *printf() functions, and Win32
- # *printf() doesn't understand %$, so we must use our /port versions,
- # which do understand %$. libintl versions >= 0.13 include their own
- # *printf versions on Win32. The libintl 0.13 release note text is:
- #
- # C format strings with positions, as they arise when a translator
- # needs to reorder a sentence, are now supported on all platforms.
- # On those few platforms (NetBSD and Woe32) for which the native
- # printf()/fprintf()/... functions don't support such format
- # strings, replacements are provided through <libintl.h>.
- #
- # We could use libintl >= 0.13's *printf() if we were sure that we had
- # a libintl >= 0.13 at runtime, but seeing that there is no clean way
- # to guarantee that, it is best to just use our own, so we are sure to
- # get %$ support. In include/port.h we disable the *printf() macros
- # that might have been defined by libintl.
- #
- # We do this unconditionally whether NLS is used or not so we are sure
- # that all Win32 libraries and binaries behave the same.
- pgac_need_repl_snprintf=yes
- else
- pgac_need_repl_snprintf=no
- for ac_func in snprintf
- do :
- ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf"
- if test "x$ac_cv_func_snprintf" = xyes; then :
- cat >>confdefs.h <<_ACEOF
- #define HAVE_SNPRINTF 1
- _ACEOF
-
- else
- pgac_need_repl_snprintf=yes
- fi
- done
-
- for ac_func in vsnprintf
- do :
- ac_fn_c_check_func "$LINENO" "vsnprintf" "ac_cv_func_vsnprintf"
- if test "x$ac_cv_func_vsnprintf" = xyes; then :
- cat >>confdefs.h <<_ACEOF
- #define HAVE_VSNPRINTF 1
- _ACEOF
-
- else
- pgac_need_repl_snprintf=yes
- fi
- done
-
- fi
-
-
- # Check whether <stdio.h> declares snprintf() and vsnprintf(); if not,
- # include/c.h will provide declarations. Note this is a separate test
- # from whether the functions exist in the C library --- there are
- # systems that have the functions but don't bother to declare them :-(
-
- ac_fn_c_check_decl "$LINENO" "snprintf" "ac_cv_have_decl_snprintf" "$ac_includes_default"
- if test "x$ac_cv_have_decl_snprintf" = xyes; then :
- ac_have_decl=1
- else
- ac_have_decl=0
- fi
-
- cat >>confdefs.h <<_ACEOF
- #define HAVE_DECL_SNPRINTF $ac_have_decl
- _ACEOF
- ac_fn_c_check_decl "$LINENO" "vsnprintf" "ac_cv_have_decl_vsnprintf" "$ac_includes_default"
- if test "x$ac_cv_have_decl_vsnprintf" = xyes; then :
- ac_have_decl=1
- else
- ac_have_decl=0
- fi
-
- cat >>confdefs.h <<_ACEOF
- #define HAVE_DECL_VSNPRINTF $ac_have_decl
- _ACEOF
-
-
-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for isinf" >&5
$as_echo_n "checking for isinf... " >&6; }
if ${ac_cv_func_isinf+:} false; then :
--- 15273,15278 ----
*************** fi
*** 16068,16120 ****
# Run tests below here
# --------------------
- # For NLS, force use of our snprintf if system's doesn't do arg control.
- # See comment above at snprintf test for details.
- if test "$enable_nls" = yes -a "$pgac_need_repl_snprintf" = no; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether snprintf supports argument control" >&5
- $as_echo_n "checking whether snprintf supports argument control... " >&6; }
- if ${pgac_cv_snprintf_arg_control+:} false; then :
- $as_echo_n "(cached) " >&6
- else
- if test "$cross_compiling" = yes; then :
- pgac_cv_snprintf_arg_control=cross
- else
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
- /* end confdefs.h. */
- #include <stdio.h>
- #include <string.h>
-
- int main()
- {
- char buf[100];
-
- /* can it swap arguments? */
- snprintf(buf, 100, "%2\$d %1\$d", 3, 4);
- if (strcmp(buf, "4 3") != 0)
- return 1;
- return 0;
- }
- _ACEOF
- if ac_fn_c_try_run "$LINENO"; then :
- pgac_cv_snprintf_arg_control=yes
- else
- pgac_cv_snprintf_arg_control=no
- fi
- rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
- conftest.$ac_objext conftest.beam conftest.$ac_ext
- fi
-
-
- fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_snprintf_arg_control" >&5
- $as_echo "$pgac_cv_snprintf_arg_control" >&6; }
-
- if test $pgac_cv_snprintf_arg_control != yes ; then
- pgac_need_repl_snprintf=yes
- fi
- fi
-
-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether long int is 64 bits" >&5
$as_echo_n "checking whether long int is 64 bits... " >&6; }
--- 15977,15982 ----
*************** _ACEOF
*** 16294,16301 ****
# Select the printf length modifier that goes with that, too.
- # (This used to be bound up with replacement-snprintf selection, but now
- # we assume that the native *printf functions use standard length modifiers.)
if test x"$pg_int64_type" = x"long long int" ; then
INT64_MODIFIER='"ll"'
else
--- 16156,16161 ----
*************** cat >>confdefs.h <<_ACEOF
*** 16308,16427 ****
_ACEOF
- # Force use of our snprintf if the system's doesn't support the %z flag.
- # (Note this test uses PG_INT64_TYPE and INT64_MODIFIER.)
- if test "$pgac_need_repl_snprintf" = no; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether snprintf supports the %z modifier" >&5
- $as_echo_n "checking whether snprintf supports the %z modifier... " >&6; }
- if ${pgac_cv_snprintf_size_t_support+:} false; then :
- $as_echo_n "(cached) " >&6
- else
- if test "$cross_compiling" = yes; then :
- pgac_cv_snprintf_size_t_support=cross
- else
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
- /* end confdefs.h. */
- #include <stdio.h>
- #include <string.h>
-
- int main()
- {
- char bufz[100];
- char buf64[100];
-
- /*
- * Print the largest unsigned number fitting in a size_t using both %zu
- * and the previously-determined format for 64-bit integers. Note that
- * we don't run this code unless we know snprintf handles 64-bit ints.
- */
- bufz[0] = '\0'; /* in case snprintf fails to emit anything */
- snprintf(bufz, sizeof(bufz), "%zu", ~((size_t) 0));
- snprintf(buf64, sizeof(buf64), "%" INT64_MODIFIER "u",
- (unsigned PG_INT64_TYPE) ~((size_t) 0));
- if (strcmp(bufz, buf64) != 0)
- return 1;
- return 0;
- }
- _ACEOF
- if ac_fn_c_try_run "$LINENO"; then :
- pgac_cv_snprintf_size_t_support=yes
- else
- pgac_cv_snprintf_size_t_support=no
- fi
- rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
- conftest.$ac_objext conftest.beam conftest.$ac_ext
- fi
-
-
- fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_snprintf_size_t_support" >&5
- $as_echo "$pgac_cv_snprintf_size_t_support" >&6; }
-
- if test "$pgac_cv_snprintf_size_t_support" != yes; then
- pgac_need_repl_snprintf=yes
- fi
- fi
-
- # Force use of our snprintf if the system's doesn't handle buffer overrun
- # as specified by C99.
- if test "$pgac_need_repl_snprintf" = no; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether snprintf handles buffer overrun per C99" >&5
- $as_echo_n "checking whether snprintf handles buffer overrun per C99... " >&6; }
- if ${pgac_cv_snprintf_c99_result+:} false; then :
- $as_echo_n "(cached) " >&6
- else
- if test "$cross_compiling" = yes; then :
- pgac_cv_snprintf_c99_result=cross
- else
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
- /* end confdefs.h. */
- #include <stdio.h>
- #include <string.h>
-
- int main()
- {
- char buf[10];
-
- strcpy(buf, "abcdefghi");
- if (snprintf(buf, 4, "%d", 123456) != 6)
- return 1;
- if (strcmp(buf, "123") != 0 || buf[4] != 'e')
- return 1;
- return 0;
- }
- _ACEOF
- if ac_fn_c_try_run "$LINENO"; then :
- pgac_cv_snprintf_c99_result=yes
- else
- pgac_cv_snprintf_c99_result=no
- fi
- rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
- conftest.$ac_objext conftest.beam conftest.$ac_ext
- fi
-
-
- fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_snprintf_c99_result" >&5
- $as_echo "$pgac_cv_snprintf_c99_result" >&6; }
-
- if test "$pgac_cv_snprintf_c99_result" != yes; then
- pgac_need_repl_snprintf=yes
- fi
- fi
-
- # Now we have checked all the reasons to replace snprintf
- if test $pgac_need_repl_snprintf = yes; then
-
- $as_echo "#define USE_REPL_SNPRINTF 1" >>confdefs.h
-
- case " $LIBOBJS " in
- *" snprintf.$ac_objext "* ) ;;
- *) LIBOBJS="$LIBOBJS snprintf.$ac_objext"
- ;;
- esac
-
- fi
-
# has to be down here, rather than with the other builtins, because
# the test uses PG_INT64_TYPE.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_mul_overflow" >&5
--- 16168,16173 ----
diff --git a/configure.in b/configure.in
index 3adec10..aca5503 100644
*** a/configure.in
--- b/configure.in
*************** if test "$pgac_cv_var_PS_STRINGS" = yes
*** 1584,1636 ****
fi
- # We use our snprintf.c emulation if either snprintf() or vsnprintf()
- # is missing. Yes, there are machines that have only one. We may
- # also decide to use snprintf.c if snprintf() is present but does not
- # have all the features we need --- see below.
-
- if test "$PORTNAME" = "win32"; then
- # Win32 gets snprintf.c built unconditionally.
- #
- # To properly translate all NLS languages strings, we must support the
- # *printf() %$ format, which allows *printf() arguments to be selected
- # by position in the translated string.
- #
- # libintl versions < 0.13 use the native *printf() functions, and Win32
- # *printf() doesn't understand %$, so we must use our /port versions,
- # which do understand %$. libintl versions >= 0.13 include their own
- # *printf versions on Win32. The libintl 0.13 release note text is:
- #
- # C format strings with positions, as they arise when a translator
- # needs to reorder a sentence, are now supported on all platforms.
- # On those few platforms (NetBSD and Woe32) for which the native
- # printf()/fprintf()/... functions don't support such format
- # strings, replacements are provided through <libintl.h>.
- #
- # We could use libintl >= 0.13's *printf() if we were sure that we had
- # a libintl >= 0.13 at runtime, but seeing that there is no clean way
- # to guarantee that, it is best to just use our own, so we are sure to
- # get %$ support. In include/port.h we disable the *printf() macros
- # that might have been defined by libintl.
- #
- # We do this unconditionally whether NLS is used or not so we are sure
- # that all Win32 libraries and binaries behave the same.
- pgac_need_repl_snprintf=yes
- else
- pgac_need_repl_snprintf=no
- AC_CHECK_FUNCS(snprintf, [], pgac_need_repl_snprintf=yes)
- AC_CHECK_FUNCS(vsnprintf, [], pgac_need_repl_snprintf=yes)
- fi
-
-
- # Check whether <stdio.h> declares snprintf() and vsnprintf(); if not,
- # include/c.h will provide declarations. Note this is a separate test
- # from whether the functions exist in the C library --- there are
- # systems that have the functions but don't bother to declare them :-(
-
- AC_CHECK_DECLS([snprintf, vsnprintf])
-
-
dnl Cannot use AC_CHECK_FUNC because isinf may be a macro
AC_CACHE_CHECK([for isinf], ac_cv_func_isinf,
[AC_LINK_IFELSE([AC_LANG_PROGRAM([
--- 1584,1589 ----
*************** for the exact reason.]])],
*** 1800,1815 ****
# Run tests below here
# --------------------
- # For NLS, force use of our snprintf if system's doesn't do arg control.
- # See comment above at snprintf test for details.
- if test "$enable_nls" = yes -a "$pgac_need_repl_snprintf" = no; then
- PGAC_FUNC_SNPRINTF_ARG_CONTROL
- if test $pgac_cv_snprintf_arg_control != yes ; then
- pgac_need_repl_snprintf=yes
- fi
- fi
-
-
dnl Check to see if we have a working 64-bit integer type.
dnl Since Postgres 8.4, we no longer support compilers without a working
dnl 64-bit type; but we have to determine whether that type is called
--- 1753,1758 ----
*************** AC_DEFINE_UNQUOTED(PG_INT64_TYPE, $pg_in
*** 1832,1839 ****
[Define to the name of a signed 64-bit integer type.])
# Select the printf length modifier that goes with that, too.
- # (This used to be bound up with replacement-snprintf selection, but now
- # we assume that the native *printf functions use standard length modifiers.)
if test x"$pg_int64_type" = x"long long int" ; then
INT64_MODIFIER='"ll"'
else
--- 1775,1780 ----
*************** fi
*** 1843,1872 ****
AC_DEFINE_UNQUOTED(INT64_MODIFIER, $INT64_MODIFIER,
[Define to the appropriate printf length modifier for 64-bit ints.])
- # Force use of our snprintf if the system's doesn't support the %z flag.
- # (Note this test uses PG_INT64_TYPE and INT64_MODIFIER.)
- if test "$pgac_need_repl_snprintf" = no; then
- PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
- if test "$pgac_cv_snprintf_size_t_support" != yes; then
- pgac_need_repl_snprintf=yes
- fi
- fi
-
- # Force use of our snprintf if the system's doesn't handle buffer overrun
- # as specified by C99.
- if test "$pgac_need_repl_snprintf" = no; then
- PGAC_FUNC_SNPRINTF_C99_RESULT
- if test "$pgac_cv_snprintf_c99_result" != yes; then
- pgac_need_repl_snprintf=yes
- fi
- fi
-
- # Now we have checked all the reasons to replace snprintf
- if test $pgac_need_repl_snprintf = yes; then
- AC_DEFINE(USE_REPL_SNPRINTF, 1, [Use replacement snprintf() functions.])
- AC_LIBOBJ(snprintf)
- fi
-
# has to be down here, rather than with the other builtins, because
# the test uses PG_INT64_TYPE.
PGAC_C_BUILTIN_OP_OVERFLOW
--- 1784,1789 ----
diff --git a/src/backend/lib/stringinfo.c b/src/backend/lib/stringinfo.c
index 798a823..df7e01f 100644
*** a/src/backend/lib/stringinfo.c
--- b/src/backend/lib/stringinfo.c
*************** resetStringInfo(StringInfo str)
*** 77,88 ****
--- 77,91 ----
void
appendStringInfo(StringInfo str, const char *fmt,...)
{
+ int save_errno = errno;
+
for (;;)
{
va_list args;
int needed;
/* Try to format the data. */
+ errno = save_errno;
va_start(args, fmt);
needed = appendStringInfoVA(str, fmt, args);
va_end(args);
*************** appendStringInfo(StringInfo str, const c
*** 105,110 ****
--- 108,116 ----
* pass the return value to enlargeStringInfo() before trying again; see
* appendStringInfo for standard usage pattern.
*
+ * Caution: callers must be sure to preserve their entry-time errno
+ * when looping, in case the fmt contains "%m".
+ *
* XXX This API is ugly, but there seems no alternative given the C spec's
* restrictions on what can portably be done with va_list arguments: you have
* to redo va_start before you can rescan the argument list, and we can't do
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 22e5d87..b9c1130 100644
*** a/src/backend/utils/error/elog.c
--- b/src/backend/utils/error/elog.c
*************** static void write_csvlog(ErrorData *edat
*** 177,183 ****
static void send_message_to_server_log(ErrorData *edata);
static void write_pipe_chunks(char *data, int len, int dest);
static void send_message_to_frontend(ErrorData *edata);
- static char *expand_fmt_string(const char *fmt, ErrorData *edata);
static const char *error_severity(int elevel);
static void append_with_tabs(StringInfo buf, const char *str);
static bool is_log_level_output(int elevel, int log_min_level);
--- 177,182 ----
*************** errcode_for_socket_access(void)
*** 705,717 ****
*/
#define EVALUATE_MESSAGE(domain, targetfield, appendval, translateit) \
{ \
- char *fmtbuf; \
StringInfoData buf; \
/* Internationalize the error format string */ \
if ((translateit) && !in_error_recursion_trouble()) \
fmt = dgettext((domain), fmt); \
- /* Expand %m in format string */ \
- fmtbuf = expand_fmt_string(fmt, edata); \
initStringInfo(&buf); \
if ((appendval) && edata->targetfield) { \
appendStringInfoString(&buf, edata->targetfield); \
--- 704,713 ----
*************** errcode_for_socket_access(void)
*** 722,736 ****
{ \
va_list args; \
int needed; \
va_start(args, fmt); \
! needed = appendStringInfoVA(&buf, fmtbuf, args); \
va_end(args); \
if (needed == 0) \
break; \
enlargeStringInfo(&buf, needed); \
} \
- /* Done with expanded fmt */ \
- pfree(fmtbuf); \
/* Save the completed message into the stack item */ \
if (edata->targetfield) \
pfree(edata->targetfield); \
--- 718,731 ----
{ \
va_list args; \
int needed; \
+ errno = edata->saved_errno; \
va_start(args, fmt); \
! needed = appendStringInfoVA(&buf, fmt, args); \
va_end(args); \
if (needed == 0) \
break; \
enlargeStringInfo(&buf, needed); \
} \
/* Save the completed message into the stack item */ \
if (edata->targetfield) \
pfree(edata->targetfield); \
*************** errcode_for_socket_access(void)
*** 746,760 ****
#define EVALUATE_MESSAGE_PLURAL(domain, targetfield, appendval) \
{ \
const char *fmt; \
- char *fmtbuf; \
StringInfoData buf; \
/* Internationalize the error format string */ \
if (!in_error_recursion_trouble()) \
fmt = dngettext((domain), fmt_singular, fmt_plural, n); \
else \
fmt = (n == 1 ? fmt_singular : fmt_plural); \
- /* Expand %m in format string */ \
- fmtbuf = expand_fmt_string(fmt, edata); \
initStringInfo(&buf); \
if ((appendval) && edata->targetfield) { \
appendStringInfoString(&buf, edata->targetfield); \
--- 741,752 ----
*************** errcode_for_socket_access(void)
*** 765,779 ****
{ \
va_list args; \
int needed; \
va_start(args, n); \
! needed = appendStringInfoVA(&buf, fmtbuf, args); \
va_end(args); \
if (needed == 0) \
break; \
enlargeStringInfo(&buf, needed); \
} \
- /* Done with expanded fmt */ \
- pfree(fmtbuf); \
/* Save the completed message into the stack item */ \
if (edata->targetfield) \
pfree(edata->targetfield); \
--- 757,770 ----
{ \
va_list args; \
int needed; \
+ errno = edata->saved_errno; \
va_start(args, n); \
! needed = appendStringInfoVA(&buf, fmt, args); \
va_end(args); \
if (needed == 0) \
break; \
enlargeStringInfo(&buf, needed); \
} \
/* Save the completed message into the stack item */ \
if (edata->targetfield) \
pfree(edata->targetfield); \
*************** send_message_to_frontend(ErrorData *edat
*** 3329,3387 ****
/*
- * expand_fmt_string --- process special format codes in a format string
- *
- * We must replace %m with the appropriate strerror string, since vsnprintf
- * won't know what to do with it.
- *
- * The result is a palloc'd string.
- */
- static char *
- expand_fmt_string(const char *fmt, ErrorData *edata)
- {
- StringInfoData buf;
- const char *cp;
-
- initStringInfo(&buf);
-
- for (cp = fmt; *cp; cp++)
- {
- if (cp[0] == '%' && cp[1] != '\0')
- {
- cp++;
- if (*cp == 'm')
- {
- /*
- * Replace %m by system error string. If there are any %'s in
- * the string, we'd better double them so that vsnprintf won't
- * misinterpret.
- */
- const char *cp2;
-
- cp2 = strerror(edata->saved_errno);
- for (; *cp2; cp2++)
- {
- if (*cp2 == '%')
- appendStringInfoCharMacro(&buf, '%');
- appendStringInfoCharMacro(&buf, *cp2);
- }
- }
- else
- {
- /* copy % and next char --- this avoids trouble with %%m */
- appendStringInfoCharMacro(&buf, '%');
- appendStringInfoCharMacro(&buf, *cp);
- }
- }
- else
- appendStringInfoCharMacro(&buf, *cp);
- }
-
- return buf.data;
- }
-
-
- /*
* error_severity --- get string representing elevel
*
* The string is not localized here, but we mark the strings for translation
--- 3320,3325 ----
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 45a391b..7f3b4ba 100644
*** a/src/bin/pg_dump/pg_backup_archiver.c
--- b/src/bin/pg_dump/pg_backup_archiver.c
*************** archputs(const char *s, Archive *AH)
*** 1471,1476 ****
--- 1471,1477 ----
int
archprintf(Archive *AH, const char *fmt,...)
{
+ int save_errno = errno;
char *p;
size_t len = 128; /* initial assumption about buffer size */
size_t cnt;
*************** archprintf(Archive *AH, const char *fmt,
*** 1483,1488 ****
--- 1484,1490 ----
p = (char *) pg_malloc(len);
/* Try to format the data. */
+ errno = save_errno;
va_start(args, fmt);
cnt = pvsnprintf(p, len, fmt, args);
va_end(args);
*************** RestoreOutput(ArchiveHandle *AH, OutputC
*** 1604,1609 ****
--- 1606,1612 ----
int
ahprintf(ArchiveHandle *AH, const char *fmt,...)
{
+ int save_errno = errno;
char *p;
size_t len = 128; /* initial assumption about buffer size */
size_t cnt;
*************** ahprintf(ArchiveHandle *AH, const char *
*** 1616,1621 ****
--- 1619,1625 ----
p = (char *) pg_malloc(len);
/* Try to format the data. */
+ errno = save_errno;
va_start(args, fmt);
cnt = pvsnprintf(p, len, fmt, args);
va_end(args);
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index 007be12..407a56d 100644
*** a/src/bin/pg_dump/pg_backup_tar.c
--- b/src/bin/pg_dump/pg_backup_tar.c
*************** _EndBlobs(ArchiveHandle *AH, TocEntry *t
*** 1026,1031 ****
--- 1026,1032 ----
static int
tarPrintf(ArchiveHandle *AH, TAR_MEMBER *th, const char *fmt,...)
{
+ int save_errno = errno;
char *p;
size_t len = 128; /* initial assumption about buffer size */
size_t cnt;
*************** tarPrintf(ArchiveHandle *AH, TAR_MEMBER
*** 1038,1043 ****
--- 1039,1045 ----
p = (char *) pg_malloc(len);
/* Try to format the data. */
+ errno = save_errno;
va_start(args, fmt);
cnt = pvsnprintf(p, len, fmt, args);
va_end(args);
diff --git a/src/common/psprintf.c b/src/common/psprintf.c
index 04465a1..2cf100f 100644
*** a/src/common/psprintf.c
--- b/src/common/psprintf.c
***************
*** 45,50 ****
--- 45,51 ----
char *
psprintf(const char *fmt,...)
{
+ int save_errno = errno;
size_t len = 128; /* initial assumption about buffer size */
for (;;)
*************** psprintf(const char *fmt,...)
*** 60,65 ****
--- 61,67 ----
result = (char *) palloc(len);
/* Try to format the data. */
+ errno = save_errno;
va_start(args, fmt);
newlen = pvsnprintf(result, len, fmt, args);
va_end(args);
*************** psprintf(const char *fmt,...)
*** 89,94 ****
--- 91,99 ----
* Other error cases do not return, but exit via elog(ERROR) or exit().
* Hence, this shouldn't be used inside libpq.
*
+ * Caution: callers must be sure to preserve their entry-time errno
+ * when looping, in case the fmt contains "%m".
+ *
* Note that the semantics of the return value are not exactly C99's.
* First, we don't promise that the estimated buffer size is exactly right;
* callers must be prepared to loop multiple times to get the right size.
diff --git a/src/include/c.h b/src/include/c.h
index 1e50103..6a8a01c 100644
*** a/src/include/c.h
--- b/src/include/c.h
*************** extern void ExceptionalCondition(const c
*** 1088,1101 ****
* standard C library.
*/
- #if !HAVE_DECL_SNPRINTF
- extern int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4);
- #endif
-
- #if !HAVE_DECL_VSNPRINTF
- extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
- #endif
-
#if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC
extern int fdatasync(int fildes);
#endif
--- 1088,1093 ----
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 2861b1f..16c148b 100644
*** a/src/include/pg_config.h.in
--- b/src/include/pg_config.h.in
***************
*** 154,163 ****
don't. */
#undef HAVE_DECL_POSIX_FADVISE
- /* Define to 1 if you have the declaration of `snprintf', and to 0 if you
- don't. */
- #undef HAVE_DECL_SNPRINTF
-
/* Define to 1 if you have the declaration of `strlcat', and to 0 if you
don't. */
#undef HAVE_DECL_STRLCAT
--- 154,159 ----
***************
*** 182,191 ****
don't. */
#undef HAVE_DECL_SYS_SIGLIST
- /* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
- don't. */
- #undef HAVE_DECL_VSNPRINTF
-
/* Define to 1 if you have the `dlopen' function. */
#undef HAVE_DLOPEN
--- 178,183 ----
***************
*** 495,503 ****
/* Define to 1 if you have the `shm_open' function. */
#undef HAVE_SHM_OPEN
- /* Define to 1 if you have the `snprintf' function. */
- #undef HAVE_SNPRINTF
-
/* Define to 1 if you have spinlocks. */
#undef HAVE_SPINLOCKS
--- 487,492 ----
***************
*** 700,708 ****
/* Define to 1 if you have the <uuid/uuid.h> header file. */
#undef HAVE_UUID_UUID_H
- /* Define to 1 if you have the `vsnprintf' function. */
- #undef HAVE_VSNPRINTF
-
/* Define to 1 if you have the <wchar.h> header file. */
#undef HAVE_WCHAR_H
--- 689,694 ----
***************
*** 914,922 ****
/* Define to 1 to build with PAM support. (--with-pam) */
#undef USE_PAM
- /* Use replacement snprintf() functions. */
- #undef USE_REPL_SNPRINTF
-
/* Define to 1 to use software CRC-32C implementation (slicing-by-8). */
#undef USE_SLICING_BY_8_CRC32C
--- 900,905 ----
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index 4c68fa8..e080270 100644
*** a/src/include/pg_config.h.win32
--- b/src/include/pg_config.h.win32
***************
*** 123,132 ****
to 0 if you don't. */
#define HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN 0
- /* Define to 1 if you have the declaration of `snprintf', and to 0 if you
- don't. */
- #define HAVE_DECL_SNPRINTF 1
-
/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
don't. */
#define HAVE_DECL_STRNLEN 1
--- 123,128 ----
***************
*** 139,148 ****
don't. */
#define HAVE_DECL_STRTOULL 1
- /* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
- don't. */
- #define HAVE_DECL_VSNPRINTF 1
-
/* Define to 1 if you have the `dlopen' function. */
/* #undef HAVE_DLOPEN */
--- 135,140 ----
***************
*** 361,369 ****
/* Define to 1 if you have the `setsid' function. */
/* #undef HAVE_SETSID */
- /* Define to 1 if you have the `snprintf' function. */
- /* #undef HAVE_SNPRINTF */
-
/* Define to 1 if you have spinlocks. */
#define HAVE_SPINLOCKS 1
--- 353,358 ----
***************
*** 541,549 ****
/* Define to 1 if you have the <utime.h> header file. */
#define HAVE_UTIME_H 1
- /* Define to 1 if you have the `vsnprintf' function. */
- #define HAVE_VSNPRINTF 1
-
/* Define to 1 if you have the <wchar.h> header file. */
#define HAVE_WCHAR_H 1
--- 530,535 ----
***************
*** 703,711 ****
/* Define to 1 to build with PAM support. (--with-pam) */
/* #undef USE_PAM */
- /* Use replacement snprintf() functions. */
- #define USE_REPL_SNPRINTF 1
-
/* Define to 1 to use software CRC-32C implementation (slicing-by-8). */
#if (_MSC_VER < 1500)
#define USE_SLICING_BY_8_CRC32C 1
--- 689,694 ----
diff --git a/src/include/port.h b/src/include/port.h
index dae80cb..3a186b4 100644
*** a/src/include/port.h
--- b/src/include/port.h
*************** extern unsigned char pg_tolower(unsigned
*** 134,140 ****
extern unsigned char pg_ascii_toupper(unsigned char ch);
extern unsigned char pg_ascii_tolower(unsigned char ch);
! #ifdef USE_REPL_SNPRINTF
/*
* Versions of libintl >= 0.13 try to replace printf() and friends with
--- 134,145 ----
extern unsigned char pg_ascii_toupper(unsigned char ch);
extern unsigned char pg_ascii_tolower(unsigned char ch);
! /*
! * Beginning in v12, we always replace snprintf() and friends with our own
! * implementation. This symbol is no longer consulted by the core code,
! * but keep it defined anyway in case any extensions are looking at it.
! */
! #define USE_REPL_SNPRINTF 1
/*
* Versions of libintl >= 0.13 try to replace printf() and friends with
*************** extern int pg_printf(const char *fmt,...
*** 187,193 ****
#define fprintf pg_fprintf
#define printf pg_printf
#endif
- #endif /* USE_REPL_SNPRINTF */
/* Replace strerror() with our own, somewhat more robust wrapper */
extern char *pg_strerror(int errnum);
--- 192,197 ----
diff --git a/src/interfaces/ecpg/compatlib/Makefile b/src/interfaces/ecpg/compatlib/Makefile
index b7bd162..e07a7fa 100644
*** a/src/interfaces/ecpg/compatlib/Makefile
--- b/src/interfaces/ecpg/compatlib/Makefile
*************** SHLIB_EXPORTS = exports.txt
*** 31,37 ****
# Need to recompile any libpgport object files
LIBS := $(filter-out -lpgport, $(LIBS))
! OBJS= informix.o strerror.o $(filter snprintf.o strnlen.o, $(LIBOBJS)) $(WIN32RES)
PKG_CONFIG_REQUIRES_PRIVATE = libecpg libpgtypes
--- 31,38 ----
# Need to recompile any libpgport object files
LIBS := $(filter-out -lpgport, $(LIBS))
! OBJS= informix.o snprintf.o strerror.o \
! $(filter strnlen.o, $(LIBOBJS)) $(WIN32RES)
PKG_CONFIG_REQUIRES_PRIVATE = libecpg libpgtypes
diff --git a/src/interfaces/ecpg/ecpglib/Makefile b/src/interfaces/ecpg/ecpglib/Makefile
index 005d25a..b381623 100644
*** a/src/interfaces/ecpg/ecpglib/Makefile
--- b/src/interfaces/ecpg/ecpglib/Makefile
*************** override CFLAGS += $(PTHREAD_CFLAGS)
*** 26,33 ****
LIBS := $(filter-out -lpgport, $(LIBS))
OBJS= execute.o typename.o descriptor.o sqlda.o data.o error.o prepare.o memory.o \
! connect.o misc.o path.o pgstrcasecmp.o strerror.o \
! $(filter snprintf.o strlcpy.o strnlen.o win32setlocale.o isinf.o, $(LIBOBJS)) \
$(WIN32RES)
# thread.c is needed only for non-WIN32 implementation of path.c
--- 26,33 ----
LIBS := $(filter-out -lpgport, $(LIBS))
OBJS= execute.o typename.o descriptor.o sqlda.o data.o error.o prepare.o memory.o \
! connect.o misc.o path.o pgstrcasecmp.o snprintf.o strerror.o \
! $(filter strlcpy.o strnlen.o win32setlocale.o isinf.o, $(LIBOBJS)) \
$(WIN32RES)
# thread.c is needed only for non-WIN32 implementation of path.c
diff --git a/src/interfaces/ecpg/pgtypeslib/Makefile b/src/interfaces/ecpg/pgtypeslib/Makefile
index 18b2402..15d7f33 100644
*** a/src/interfaces/ecpg/pgtypeslib/Makefile
--- b/src/interfaces/ecpg/pgtypeslib/Makefile
*************** SHLIB_LINK += $(filter -lm, $(LIBS))
*** 30,37 ****
SHLIB_EXPORTS = exports.txt
OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \
! pgstrcasecmp.o strerror.o \
! $(filter rint.o snprintf.o strnlen.o, $(LIBOBJS)) \
string.o \
$(WIN32RES)
--- 30,37 ----
SHLIB_EXPORTS = exports.txt
OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \
! pgstrcasecmp.o snprintf.o strerror.o \
! $(filter rint.o strnlen.o, $(LIBOBJS)) \
string.o \
$(WIN32RES)
diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile
index 9af7cc0..a694560 100644
*** a/src/interfaces/libpq/Makefile
--- b/src/interfaces/libpq/Makefile
*************** OBJS= fe-auth.o fe-auth-scram.o fe-conne
*** 36,44 ****
libpq-events.o
# libpgport C files we always use
OBJS += chklocale.o inet_net_ntop.o noblock.o pgstrcasecmp.o pqsignal.o \
! strerror.o thread.o
# libpgport C files that are needed if identified by configure
! OBJS += $(filter crypt.o getaddrinfo.o getpeereid.o inet_aton.o open.o system.o snprintf.o strlcpy.o strnlen.o win32error.o win32setlocale.o, $(LIBOBJS))
ifeq ($(enable_strong_random), yes)
OBJS += pg_strong_random.o
--- 36,44 ----
libpq-events.o
# libpgport C files we always use
OBJS += chklocale.o inet_net_ntop.o noblock.o pgstrcasecmp.o pqsignal.o \
! snprintf.o strerror.o thread.o
# libpgport C files that are needed if identified by configure
! OBJS += $(filter crypt.o getaddrinfo.o getpeereid.o inet_aton.o open.o system.o strlcpy.o strnlen.o win32error.o win32setlocale.o, $(LIBOBJS))
ifeq ($(enable_strong_random), yes)
OBJS += pg_strong_random.o
diff --git a/src/interfaces/libpq/pqexpbuffer.c b/src/interfaces/libpq/pqexpbuffer.c
index 0814ec6..43c36c3 100644
*** a/src/interfaces/libpq/pqexpbuffer.c
--- b/src/interfaces/libpq/pqexpbuffer.c
*************** enlargePQExpBuffer(PQExpBuffer str, size
*** 233,238 ****
--- 233,239 ----
void
printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
{
+ int save_errno = errno;
va_list args;
bool done;
*************** printfPQExpBuffer(PQExpBuffer str, const
*** 244,249 ****
--- 245,251 ----
/* Loop in case we have to retry after enlarging the buffer. */
do
{
+ errno = save_errno;
va_start(args, fmt);
done = appendPQExpBufferVA(str, fmt, args);
va_end(args);
*************** printfPQExpBuffer(PQExpBuffer str, const
*** 261,266 ****
--- 263,269 ----
void
appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
{
+ int save_errno = errno;
va_list args;
bool done;
*************** appendPQExpBuffer(PQExpBuffer str, const
*** 270,275 ****
--- 273,279 ----
/* Loop in case we have to retry after enlarging the buffer. */
do
{
+ errno = save_errno;
va_start(args, fmt);
done = appendPQExpBufferVA(str, fmt, args);
va_end(args);
*************** appendPQExpBuffer(PQExpBuffer str, const
*** 281,286 ****
--- 285,293 ----
* Shared guts of printfPQExpBuffer/appendPQExpBuffer.
* Attempt to format data and append it to str. Returns true if done
* (either successful or hard failure), false if need to retry.
+ *
+ * Caution: callers must be sure to preserve their entry-time errno
+ * when looping, in case the fmt contains "%m".
*/
static bool
appendPQExpBufferVA(PQExpBuffer str, const char *fmt, va_list args)
diff --git a/src/pl/plperl/plperl.h b/src/pl/plperl/plperl.h
index e6241f0..f8888a4 100644
*** a/src/pl/plperl/plperl.h
--- b/src/pl/plperl/plperl.h
***************
*** 29,39 ****
* Sometimes perl carefully scribbles on our *printf macros.
* So we undefine them here and redefine them after it's done its dirty deed.
*/
-
- #ifdef USE_REPL_SNPRINTF
#undef snprintf
#undef vsnprintf
- #endif
/*
* ActivePerl 5.18 and later are MinGW-built, and their headers use GCC's
--- 29,36 ----
***************
*** 99,105 ****
#endif
/* put back our snprintf and vsnprintf */
- #ifdef USE_REPL_SNPRINTF
#ifdef snprintf
#undef snprintf
#endif
--- 96,101 ----
***************
*** 113,119 ****
#define vsnprintf pg_vsnprintf
#define snprintf pg_snprintf
#endif /* __GNUC__ */
- #endif /* USE_REPL_SNPRINTF */
/* perl version and platform portability */
#define NEED_eval_pv
--- 109,114 ----
diff --git a/src/pl/plpython/plpy_elog.c b/src/pl/plpython/plpy_elog.c
index e244104..3814a6c 100644
*** a/src/pl/plpython/plpy_elog.c
--- b/src/pl/plpython/plpy_elog.c
*************** static bool set_string_attr(PyObject *ob
*** 46,51 ****
--- 46,52 ----
void
PLy_elog_impl(int elevel, const char *fmt,...)
{
+ int save_errno = errno;
char *xmsg;
char *tbmsg;
int tb_depth;
*************** PLy_elog_impl(int elevel, const char *fm
*** 96,101 ****
--- 97,103 ----
va_list ap;
int needed;
+ errno = save_errno;
va_start(ap, fmt);
needed = appendStringInfoVA(&emsg, dgettext(TEXTDOMAIN, fmt), ap);
va_end(ap);
diff --git a/src/pl/plpython/plpython.h b/src/pl/plpython/plpython.h
index 6cc323a..aefbfc2 100644
*** a/src/pl/plpython/plpython.h
--- b/src/pl/plpython/plpython.h
***************
*** 33,43 ****
* Sometimes python carefully scribbles on our *printf macros.
* So we undefine them here and redefine them after it's done its dirty deed.
*/
-
- #ifdef USE_REPL_SNPRINTF
#undef snprintf
#undef vsnprintf
- #endif
#if defined(_MSC_VER) && defined(_DEBUG)
/* Python uses #pragma to bring in a non-default libpython on VC++ if
--- 33,40 ----
*************** typedef int Py_ssize_t;
*** 124,130 ****
#include <eval.h>
/* put back our snprintf and vsnprintf */
- #ifdef USE_REPL_SNPRINTF
#ifdef snprintf
#undef snprintf
#endif
--- 121,126 ----
*************** typedef int Py_ssize_t;
*** 138,144 ****
#define vsnprintf pg_vsnprintf
#define snprintf pg_snprintf
#endif /* __GNUC__ */
- #endif /* USE_REPL_SNPRINTF */
/*
* Used throughout, and also by the Python 2/3 porting layer, so it's easier to
--- 134,139 ----
diff --git a/src/port/Makefile b/src/port/Makefile
index b3a10ba..a2ee8e2 100644
*** a/src/port/Makefile
--- b/src/port/Makefile
*************** LIBS += $(PTHREAD_LIBS)
*** 33,39 ****
OBJS = $(LIBOBJS) $(PG_CRC32C_OBJS) chklocale.o erand48.o inet_net_ntop.o \
noblock.o path.o pgcheckdir.o pgmkdirp.o pgsleep.o \
pgstrcasecmp.o pqsignal.o \
! qsort.o qsort_arg.o quotes.o sprompt.o strerror.o tar.o thread.o
ifeq ($(enable_strong_random), yes)
OBJS += pg_strong_random.o
--- 33,40 ----
OBJS = $(LIBOBJS) $(PG_CRC32C_OBJS) chklocale.o erand48.o inet_net_ntop.o \
noblock.o path.o pgcheckdir.o pgmkdirp.o pgsleep.o \
pgstrcasecmp.o pqsignal.o \
! qsort.o qsort_arg.o quotes.o snprintf.o sprompt.o strerror.o \
! tar.o thread.o
ifeq ($(enable_strong_random), yes)
OBJS += pg_strong_random.o
diff --git a/src/port/README b/src/port/README
index 4ae96da..c446b46 100644
*** a/src/port/README
--- b/src/port/README
*************** and adding infrastructure to recompile t
*** 18,24 ****
OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
connect.o misc.o path.o exec.o \
! $(filter snprintf.o, $(LIBOBJS))
The problem is that there is no testing of which object files need to be
added, but missing functions usually show up when linking user
--- 18,24 ----
OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
connect.o misc.o path.o exec.o \
! $(filter strlcat.o, $(LIBOBJS))
The problem is that there is no testing of which object files need to be
added, but missing functions usually show up when linking user
diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index 851e2ae..63cec5d 100644
*** a/src/port/snprintf.c
--- b/src/port/snprintf.c
***************
*** 64,69 ****
--- 64,77 ----
*
* 5. Space and '#' flags are not implemented.
*
+ * In addition, we support some extensions over C99:
+ *
+ * 1. Argument order control through "%n$" and "*n$", as required by POSIX.
+ *
+ * 2. "%m" expands to the value of strerror(errno), where errno is the
+ * value that variable had at the start of the call. This is a glibc
+ * extension, but a very useful one.
+ *
*
* Historically the result values of sprintf/snprintf varied across platforms.
* This implementation now follows the C99 standard:
*************** static void flushbuffer(PrintfTarget *ta
*** 155,160 ****
--- 163,175 ----
static void dopr(PrintfTarget *target, const char *format, va_list args);
+ /*
+ * Externally visible entry points.
+ *
+ * All of these are just wrappers around dopr(). Note it's essential that
+ * they not change the value of "errno" before reaching dopr().
+ */
+
int
pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
{
*************** static void trailing_pad(int *padlen, Pr
*** 315,325 ****
/*
! * dopr(): poor man's version of doprintf
*/
static void
dopr(PrintfTarget *target, const char *format, va_list args)
{
const char *format_start = format;
int ch;
bool have_dollar;
--- 330,341 ----
/*
! * dopr(): the guts of *printf for all cases.
*/
static void
dopr(PrintfTarget *target, const char *format, va_list args)
{
+ int save_errno = errno;
const char *format_start = format;
int ch;
bool have_dollar;
*************** nextch1:
*** 497,502 ****
--- 513,519 ----
else
have_non_dollar = true;
break;
+ case 'm':
case '%':
break;
}
*************** nextch2:
*** 802,807 ****
--- 819,831 ----
precision, pointflag,
target);
break;
+ case 'm':
+ {
+ const char *errm = strerror(save_errno);
+
+ dostr(errm, strlen(errm), target);
+ }
+ break;
case '%':
dopr_outch('%', target);
break;