Debian Codegraph @

m4/fpurge.m4

raw
1 # fpurge.m4
2 # serial 16
3 dnl Copyright (C) 2007, 2009-2025 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_CHECK_HEADERS_ONCE([stdio_ext.h])
13 AC_CHECK_FUNCS_ONCE([fpurge])
14 gl_CHECK_FUNCS_ANDROID([__fpurge], [[#include <stdio_ext.h>]])
15 AC_CHECK_DECLS([fpurge], , , [[#include <stdio.h>]])
16 if test $ac_cv_func_fpurge = yes; then
17 HAVE_FPURGE=1
18 # Detect BSD bug. Only cygwin 1.7 and musl are known to be immune.
19 AC_CACHE_CHECK([whether fpurge works], [gl_cv_func_fpurge_works],
20 [if test $ac_cv_have_decl_fpurge = yes; then
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 [# Obey --enable-cross-guesses.
58 gl_cv_func_fpurge_works="$gl_cross_guess_normal"
59 ])
60 else
61 gl_cv_func_fpurge_works=no
62 fi
63 ])
64 case "$gl_cv_func_fpurge_works" in
65 *yes) ;;
66 *) REPLACE_FPURGE=1 ;;
67 esac
68 else
69 HAVE_FPURGE=0
70 fi
71 if test "x$ac_cv_have_decl_fpurge" = xno; then
72 HAVE_DECL_FPURGE=0
73 fi
74 ])