Front page | perl.perl5.porters |
Postings from June 2007
Re: vsprintf
Thread Previous
From:
H.Merijn Brand
Date:
June 13, 2007 13:18
Subject:
Re: vsprintf
Message ID:
20070613201513.65f223ea@pc09
On Wed, 13 Jun 2007 14:41:44 -0400 (EDT), Andy Dougherty
<doughera@lafayette.edu> wrote:
> On Thu, 12 Apr 2007, Nicholas Clark wrote:
>
> > So we have this to determine the return value of vsprintf:
>
> [omitted]
>
> > And I get:
> >
> > vprintf() found.
> > Your vsprintf() returns (char*).
> >
> > Which is poppycock, because if I try to compile that program, I get:
> >
> > $ gcc -o try try.c
> > In file included from try.c:1:
> > /usr/include/varargs.h:34:2: #error "<varargs.h> is obsolete with this version of GCC."
> > /usr/include/varargs.h:35:2: #error "Change your code to use <stdarg.h> instead."
> > try.c:10: error: syntax error before "va_dcl"
> > try.c:11: error: syntax error before '{' token
> > try.c:12: warning: data definition has no type or storage class
> > try.c:15: warning: parameter names (without types) in function declaration
> > try.c:15: warning: data definition has no type or storage class
> > try.c:16: error: syntax error before '(' token
>
> This patch fixes that problem. There are still some murky corners dealing
> with what happens if the test program won't compile, but at least the
> resulting default guess is likely to be right.
Thanks applied in #31374 and #31375. That's what you get when doing a
subject at a time. I could easily have combined the two in one go.
> I didn't look at how this is used in util.c yet. One thing at a time.
Exactly :) One thing^wpatch at the time ...
> diff -r -u metaconfig-20070423/U/compline/d_vprintf.U metaconfig-andy/U/compline/d_vprintf.U
> --- metaconfig-20070423/U/compline/d_vprintf.U 2007-04-23 12:22:34.000000000 -0400
> +++ metaconfig-andy/U/compline/d_vprintf.U 2007-06-13 14:05:21.000000000 -0400
> @@ -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 @@
> 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
>
>
--
H.Merijn Brand Amsterdam Perl Mongers (http://amsterdam.pm.org/)
using & porting perl 5.6.2, 5.8.x, 5.9.x on HP-UX 10.20, 11.00, 11.11,
& 11.23, SuSE 10.0 & 10.2, AIX 4.3 & 5.2, and Cygwin. http://qa.perl.org
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org
http://www.goldmark.org/jeff/stupid-disclaimers/
Thread Previous