]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
(AC_LANG_INT_SAVE(C)):
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 17 Sep 2001 21:49:30 +0000 (21:49 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 17 Sep 2001 21:49:30 +0000 (21:49 +0000)
Allow expression to return any value that can fit into unsigned long
(not int, as before).  Check for output errors.

From Bruno Haible: Always include <stdio.h> and <stdlib.h>. Evaluate
the expression in an extra function before these includes. Call
fprintf "%d" only after ensuring the argument is of type 'int'.
Reported by Wayne Chapeskie <waynec@spinnaker.com>.

lib/autoconf/c.m4

index 5bdeddeca842f35eedf2eb8efe5ad55a2565db3e..18703648a3bd0c9bd94a2d34db4bee8b0465dcc2 100644 (file)
@@ -204,15 +204,27 @@ _array_ @<:@0@:>@ = 0
 
 # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
 # -----------------------------------------
-# We need `stdio.h' to open a `FILE', so the prologue defaults to the
-# inclusion of `stdio.h'.
+# We need `stdio.h' to open a `FILE' and `stdlib.h' for `exit'.
+# But we include them only after the EXPRESSION has been evaluated.
 m4_define([AC_LANG_INT_SAVE(C)],
-[AC_LANG_PROGRAM([m4_default([$1], [@%:@include <stdio.h>])],
-[FILE *f = fopen ("conftest.val", "w");
-if (!f)
+[AC_LANG_PROGRAM([$1
+unsigned long conftestval () { return $2; }
+@%:@include <stdio.h>
+@%:@include <stdlib.h>],
+[
+  FILE *f = fopen ("conftest.val", "w");
+  if (f)
+    {
+      unsigned long i = conftestval ();
+      if (0 <= ($2) && i == ($2))
+       {
+         fprintf (f, "%lu\n", i);
+         if (! ferror (f) && fclose (f) == 0)
+           exit (0);
+       }
+    }
   exit (1);
-fprintf (f, "%d", ($2));
-fclose (f);])])
+])])
 
 
 # ----------------- #