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_HEADERS_ONCE([stdio_ext.h])
12 AC_CHECK_FUNCS_ONCE([fpurge])
13 AC_CHECK_FUNCS_ONCE([__fpurge])
14 AC_CHECK_DECLS([fpurge], , , [[#include <stdio.h>]])
15 if test "x$ac_cv_func_fpurge" = xyes; then
17 # Detect BSD bug. Only cygwin 1.7 and musl are known to be immune.
18 AC_CACHE_CHECK([whether fpurge works], [gl_cv_func_fpurge_works],
23 [[FILE *f = fopen ("conftest.txt", "w+");
26 if (fputc ('a', f) != 'a')
27 { fclose (f); return 2; }
30 { fclose (f); return 3; }
32 { fclose (f); return 4; }
34 { fclose (f); return 5; }
35 if (putc ('b', f) != 'b')
36 { fclose (f); return 6; }
39 if ((f = fopen ("conftest.txt", "r")) == NULL)
42 { fclose (f); return 9; }
44 { fclose (f); return 10; }
46 { fclose (f); return 11; }
49 if (remove ("conftest.txt") != 0)
53 [gl_cv_func_fpurge_works=yes],
54 [gl_cv_func_fpurge_works=no],
56 # Guess yes on musl systems.
57 *-musl*) gl_cv_func_fpurge_works="guessing yes" ;;
58 # Otherwise obey --enable-cross-guesses.
59 *) gl_cv_func_fpurge_works="$gl_cross_guess_normal" ;;
63 case "$gl_cv_func_fpurge_works" in
65 *) REPLACE_FPURGE=1 ;;
70 if test "x$ac_cv_have_decl_fpurge" = xno; then