Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b4feafb

Browse files
committed
Add support to port/snprintf.c for position parameter specification:
+ # Determine if printf supports %1$ argument selection, e.g. %5$ selects + # the fifth argument after the printf print string. + # This is not in the C99 standard, but in the Single Unix Specification (SUS). + # It is used in our langauge translation strings. Nicolai Tufar with configure changes by Bruce.
1 parent 78bb800 commit b4feafb

File tree

4 files changed

+295
-17
lines changed

4 files changed

+295
-17
lines changed

config/c-library.m4

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Macros that test various C library quirks
2-
# $PostgreSQL: pgsql/config/c-library.m4,v 1.29 2004/12/16 17:48:26 momjian Exp $
2+
# $PostgreSQL: pgsql/config/c-library.m4,v 1.30 2005/02/22 03:55:50 momjian Exp $
33

44

55
# PGAC_VAR_INT_TIMEZONE
@@ -266,3 +266,36 @@ case $pgac_cv_snprintf_long_long_int_format in
266266
LONG_LONG_INT_FORMAT=$pgac_cv_snprintf_long_long_int_format;;
267267
*) AC_MSG_RESULT(none);;
268268
esac])# PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT
269+
270+
271+
# PGAC_FUNC_PRINTF_ARG_CONTROL
272+
# ---------------------------------------
273+
# Determine if printf supports %1$ argument selection, e.g. %5$ selects
274+
# the fifth argument after the printf print string.
275+
# This is not in the C99 standard, but in the Single Unix Specification (SUS).
276+
# It is used in our langauge translation strings.
277+
#
278+
AC_DEFUN([PGAC_FUNC_PRINTF_ARG_CONTROL],
279+
[AC_MSG_CHECKING([printf supports argument control])
280+
AC_CACHE_VAL(pgac_cv_printf_arg_control,
281+
[AC_TRY_RUN([#include <stdio.h>
282+
283+
int does_printf_have_arg_control()
284+
{
285+
char buf[100];
286+
287+
/* can it swap arguments? */
288+
snprintf(buf, 100, "%2$d|%1$d", 3, 4);
289+
if (strcmp(buf, "4|3") != 0)
290+
return 0;
291+
return 1;
292+
}
293+
main() {
294+
exit(! does_printf_have_arg_control());
295+
}],
296+
[pgac_cv_printf_arg_control=yes],
297+
[pgac_cv_printf_arg_control=no],
298+
[pgac_cv_printf_arg_control=cross])
299+
])dnl AC_CACHE_VAL
300+
AC_MSG_RESULT([$pgac_cv_printf_arg_control])
301+
])# PGAC_FUNC_PRINTF_ARG_CONTROL

configure

+57
Original file line numberDiff line numberDiff line change
@@ -12162,6 +12162,63 @@ fi
1216212162
done
1216312163

1216412164

12165+
echo "$as_me:$LINENO: checking printf supports argument control" >&5
12166+
echo $ECHO_N "checking printf supports argument control... $ECHO_C" >&6
12167+
if test "${pgac_cv_printf_arg_control+set}" = set; then
12168+
echo $ECHO_N "(cached) $ECHO_C" >&6
12169+
else
12170+
if test "$cross_compiling" = yes; then
12171+
pgac_cv_printf_arg_control=cross
12172+
else
12173+
cat >conftest.$ac_ext <<_ACEOF
12174+
#line $LINENO "configure"
12175+
#include "confdefs.h"
12176+
#include <stdio.h>
12177+
12178+
int does_printf_have_arg_control()
12179+
{
12180+
char buf[100];
12181+
12182+
/* can it swap arguments? */
12183+
snprintf(buf, 100, "%2$d|%1$d", 3, 4);
12184+
if (strcmp(buf, "4|3") != 0)
12185+
return 0;
12186+
return 1;
12187+
}
12188+
main() {
12189+
exit(! does_printf_have_arg_control());
12190+
}
12191+
_ACEOF
12192+
rm -f conftest$ac_exeext
12193+
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
12194+
(eval $ac_link) 2>&5
12195+
ac_status=$?
12196+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
12197+
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
12198+
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
12199+
(eval $ac_try) 2>&5
12200+
ac_status=$?
12201+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
12202+
(exit $ac_status); }; }; then
12203+
pgac_cv_printf_arg_control=yes
12204+
else
12205+
echo "$as_me: program exited with status $ac_status" >&5
12206+
echo "$as_me: failed program was:" >&5
12207+
cat conftest.$ac_ext >&5
12208+
( exit $ac_status )
12209+
pgac_cv_printf_arg_control=no
12210+
fi
12211+
rm -f core core.* *.core conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
12212+
fi
12213+
12214+
fi
12215+
echo "$as_me:$LINENO: result: $pgac_cv_printf_arg_control" >&5
12216+
echo "${ECHO_T}$pgac_cv_printf_arg_control" >&6
12217+
12218+
# cross compiler should use our snprintf too
12219+
if test $pgac_cv_printf_arg_control != yes ; then
12220+
pgac_need_repl_snprintf=yes
12221+
fi
1216512222

1216612223
# Check whether <stdio.h> declares snprintf() and vsnprintf(); if not,
1216712224
# include/c.h will provide declarations. Note this is a separate test

configure.in

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.399 2005/01/18 05:23:36 momjian Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.400 2005/02/22 03:55:12 momjian Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -881,6 +881,11 @@ pgac_need_repl_snprintf=no
881881
AC_CHECK_FUNCS(snprintf, [], pgac_need_repl_snprintf=yes)
882882
AC_CHECK_FUNCS(vsnprintf, [], pgac_need_repl_snprintf=yes)
883883

884+
PGAC_FUNC_PRINTF_ARG_CONTROL
885+
# cross compiler should use our snprintf too
886+
if test $pgac_cv_printf_arg_control != yes ; then
887+
pgac_need_repl_snprintf=yes
888+
fi
884889

885890
# Check whether <stdio.h> declares snprintf() and vsnprintf(); if not,
886891
# include/c.h will provide declarations. Note this is a separate test
@@ -1069,6 +1074,8 @@ AC_MSG_ERROR([[
10691074
[AC_MSG_RESULT([cross-compiling])])
10701075

10711076

1077+
dnl 64-bit section
1078+
dnl
10721079
dnl Check to see if we have a working 64-bit integer type.
10731080
dnl This breaks down into two steps:
10741081
dnl (1) figure out if the compiler has a 64-bit int type with working

0 commit comments

Comments
 (0)