Debian Codegraph @

m4/fpurge.m4

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