Fix "warning: 'format' attribute argument not supported: rpl_printf".
[gnulib.git] / m4 / fpurge.m4
blob0796a6f0edda2ad8eea6f45bc9cfa989019c88fb
1 # fpurge.m4 serial 11
2 dnl Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_FPURGE],
9   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
11   AC_CHECK_FUNCS_ONCE([fpurge])
12   AC_CHECK_FUNCS_ONCE([__fpurge])
13   AC_CHECK_DECLS([fpurge], , , [[#include <stdio.h>]])
14   if test "x$ac_cv_func_fpurge" = xyes; then
15     HAVE_FPURGE=1
16     # Detect BSD bug.  Only cygwin 1.7 and musl are known to be immune.
17     AC_CACHE_CHECK([whether fpurge works], [gl_cv_func_fpurge_works],
18       [AC_RUN_IFELSE(
19          [AC_LANG_PROGRAM(
20             [[#include <stdio.h>
21 ]],
22             [[FILE *f = fopen ("conftest.txt", "w+");
23               if (!f)
24                 return 1;
25               if (fputc ('a', f) != 'a')
26                 { fclose (f); return 2; }
27               rewind (f);
28               if (fgetc (f) != 'a')
29                 { fclose (f); return 3; }
30               if (fgetc (f) != EOF)
31                 { fclose (f); return 4; }
32               if (fpurge (f) != 0)
33                 { fclose (f); return 5; }
34               if (putc ('b', f) != 'b')
35                 { fclose (f); return 6; }
36               if (fclose (f) != 0)
37                 return 7;
38               if ((f = fopen ("conftest.txt", "r")) == NULL)
39                 return 8;
40               if (fgetc (f) != 'a')
41                 { fclose (f); return 9; }
42               if (fgetc (f) != 'b')
43                 { fclose (f); return 10; }
44               if (fgetc (f) != EOF)
45                 { fclose (f); return 11; }
46               if (fclose (f) != 0)
47                 return 12;
48               if (remove ("conftest.txt") != 0)
49                 return 13;
50               return 0;
51             ]])],
52          [gl_cv_func_fpurge_works=yes],
53          [gl_cv_func_fpurge_works=no],
54          [case "$host_os" in
55                      # Guess yes on musl systems.
56             *-musl*) gl_cv_func_fpurge_works="guessing yes" ;;
57                      # Otherwise obey --enable-cross-guesses.
58             *)       gl_cv_func_fpurge_works="$gl_cross_guess_normal" ;;
59           esac
60          ])
61       ])
62     case "$gl_cv_func_fpurge_works" in
63       *yes) ;;
64       *) REPLACE_FPURGE=1 ;;
65     esac
66   else
67     HAVE_FPURGE=0
68   fi
69   if test "x$ac_cv_have_decl_fpurge" = xno; then
70     HAVE_DECL_FPURGE=0
71   fi