This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: vsprintf
authorAndy Dougherty <doughera@lafayette.edu>
Wed, 13 Jun 2007 14:41:44 +0000 (10:41 -0400)
committerH.Merijn Brand <h.m.brand@xs4all.nl>
Wed, 13 Jun 2007 20:14:24 +0000 (20:14 +0000)
Message-ID: <Pine.LNX.4.64.0706131434120.18715@fractal.phys.lafayette.edu>

p4raw-id: //depot/metaconfig@31374

U/compline/d_vprintf.U

index 3b1f8c8..34627a6 100644 (file)
@@ -12,7 +12,8 @@
 ?RCS: Revision 3.0  1993/08/18  12:07:59  ram
 ?RCS: Baseline for dist 3.0 netwide release.
 ?RCS:
-?MAKE:d_vprintf d_charvspr: Compile Guess cat Csym Setvar run rm_try i_stdlib
+?MAKE:d_vprintf d_charvspr: Compile Guess cat Csym Setvar run rm_try \
+       i_stdlib i_unistd i_stdarg i_varargs
 ?MAKE: -pick add $@ %<
 ?S:d_vprintf:
 ?S:    This variable conditionally defines the HAS_VPRINTF symbol, which
@@ -46,36 +47,73 @@ if set vprintf val -f d_vprintf; eval $csym; $val; then
        echo 'vprintf() found.' >&4
        val="$define"
        $cat >try.c <<EOF
-#include <varargs.h>
+#$i_stdarg I_STDARG  /* Only one of these can be defined by i_varhrd */
+#$i_varargs I_VARARGS
+
 #$i_stdlib I_STDLIB
+#$i_unistd I_UNISTD
+
+#ifdef I_STDARG
+#  include <stdarg.h>
+#else /* I_VARARGS */
+#  include <varargs.h>
+#endif
+
+#ifdef I_UNISTD
+#  include <unistd.h>
+#endif
+
 #ifdef I_STDLIB
-#include <stdlib.h>
+#  include <stdlib.h>
 #endif
 
-int main() { xxx("foo"); }
+#include <stdio.h> /* vsprintf prototype */
+
+#ifdef I_STDARG
+void xxx(int n, ...)
+{
+    va_list args;
+    char buf[10];
+    va_start(args, n);
+    exit((unsigned long)vsprintf(buf,"%s",args) > 10L);
+}
+int main() { xxx(1, "foo"); }
+
+#else /* I_VARARGS */
 
 xxx(va_alist)
 va_dcl
 {
-       va_list args;
-       char buf[10];
-
-       va_start(args);
-       exit((unsigned long)vsprintf(buf,"%s",args) > 10L);
+    va_list args;
+    char buf[10];
+    va_start(args);
+    exit((unsigned long)vsprintf(buf,"%s",args) > 10L);
 }
+int main() { xxx("foo"); }
+
+#endif
+
 EOF
        set try
-       if eval $compile && $run ./try; then
-               echo "Your vsprintf() returns (int)." >&4
-               val2="$undef"
+       if eval $compile_ok; then
+               if $run ./try; then
+                       echo "Your vsprintf() returns (int)." >&4
+                       val2="$undef"
+               else
+                       echo "Your vsprintf() returns (char*)." >&4
+                       val2="$define"
+               fi
        else
-               echo "Your vsprintf() returns (char*)." >&4
-               val2="$define"
+               echo 'I am unable to compile the vsprintf() test program.' >&4
+               # We shouldn't get here.  If we do, assume the standard signature,
+               # not the old BSD one.
+               echo 'Guessing that vsprintf() returns (int).' >&4
+               val2="$undef"
        fi
 else
        echo 'vprintf() NOT found.' >&4
-               val="$undef"
-               val2="$undef"
+       val="$undef"
+       val2="$undef"
 fi
 $rm_try
 set d_vprintf