[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AC_FUNC_SETVBUF_REVERSED in cross-compilation
From: |
Paul Eggert |
Subject: |
Re: AC_FUNC_SETVBUF_REVERSED in cross-compilation |
Date: |
Wed, 8 May 2002 13:05:44 -0700 (PDT) |
> From: "Paul D. Smith" <address@hidden>
> Date: 08 May 2002 12:47:51 -0400
>
> I notice that the AC_FUNC_SETVBUF_REVERSED macro has no option for how
> it behaves during cross-compilation....
>
> I have a partial solution, which is that the code uses setlinebuf() in
> preference to setvbuf() if the former exists,
I'm leery of this solution, as setlinebuf is not standardized.
setvbuf is standardized and is more likely to work correctly these days.
I would prefer setvbuf, and fall back on setlinebuf only if setvbuf
doesn't work.
> I would assume the arguments were _not_ reversed
> in a cross-compiled environment (the systems where it is reversed are
> very old and surely must be rare these days: even more rare to
> cross-compile with one as a target!)
Yes. The probability is zero, I'd say.
> Anyone else have any good ideas?
I have installed the following patch into the Autoconf CVS. It should
appear in the next version of Autoconf, and it should fix your problem.
2002-05-08 Paul Eggert <address@hidden>
* lib/autoconf/functions.m4 (AC_FUNC_SETVBUF_REVERSED):
If prototypes are supported, use them to check this at compile-time,
instead of trying to check it at run-time. If we must do a run-time
check, assume that setvbuf is standard when cross-compiling, as
nonstandard setvbuf occurs only on ancient and unlikely hosts.
--- functions.m4.~1.58.~ 2002-04-20 22:42:18.000000000 -0700
+++ functions.m4 2002-05-08 12:48:31.017280000 -0700
@@ -1295,22 +1295,42 @@ test $ac_cv_func_strnlen_working = no &&
# AC_FUNC_SETVBUF_REVERSED
# ------------------------
AC_DEFUN([AC_FUNC_SETVBUF_REVERSED],
-[AC_CACHE_CHECK(whether setvbuf arguments are reversed,
+[AC_REQUIRE([AC_C_PROTOTYPES])dnl
+AC_CACHE_CHECK(whether setvbuf arguments are reversed,
ac_cv_func_setvbuf_reversed,
-[AC_TRY_RUN([#include <stdio.h>
-/* If setvbuf has the reversed format, exit 0. */
-int
-main ()
-{
- /* This call has the arguments reversed.
- A reversed system may check and see that the address of main
- is not _IOLBF, _IONBF, or _IOFBF, and return nonzero. */
- if (setvbuf(stdout, _IOLBF, (char *) main, BUFSIZ) != 0)
- exit(1);
- putc('\r', stdout);
- exit(0); /* Non-reversed systems segv here. */
-}], ac_cv_func_setvbuf_reversed=yes, ac_cv_func_setvbuf_reversed=no)
-rm -f core core.* *.core])
+ [ac_cv_func_setvbuf_reversed=no
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stdio.h>
+# if PROTOTYPES
+ int (setvbuf) (FILE *, int, char *, size_t);
+# endif]],
+ [[char buf; return setvbuf (stdout, _IOLBF, &buf, 1);]])],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stdio.h>
+# if PROTOTYPES
+ int (setvbuf) (FILE *, int, char *, size_t);
+# endif]],
+ [[char buf; return setvbuf (stdout, &buf, _IOLBF, 1);]])],
+ [# It compiles and links either way, so it must not be declared
+ # with a prototype and most likely this is a K&R C compiler.
+ # Try running it.
+ AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stdio.h>]],
+ [[/* This call has the arguments reversed.
+ A reversed system may check and see that the address of buf
+ is not _IOLBF, _IONBF, or _IOFBF, and return nonzero. */
+ char buf;
+ if (setvbuf (stdout, _IOLBF, &buf, 1) != 0)
+ exit (1);
+ putchar ('\r');
+ exit (0); /* Non-reversed systems SEGV here. */]])],
+ ac_cv_func_setvbuf_reversed=yes,
+ rm -f core core.* *.core,
+ [[: # Assume setvbuf is not reversed when cross-compiling.]])]
+ ac_cv_func_setvbuf_reversed=yes)])])
if test $ac_cv_func_setvbuf_reversed = yes; then
AC_DEFINE(SETVBUF_REVERSED, 1,
[Define to 1 if the `setvbuf' function takes the buffering type as
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: AC_FUNC_SETVBUF_REVERSED in cross-compilation,
Paul Eggert <=