| 1 | # fpurge.m4 serial 7 |
| 2 | dnl Copyright (C) 2007, 2009-2011 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. |
| 6 | |
| 7 | AC_DEFUN([gl_FUNC_FPURGE], |
| 8 | [ |
| 9 | AC_REQUIRE([gl_STDIO_H_DEFAULTS]) |
| 10 | AC_CHECK_FUNCS_ONCE([fpurge]) |
| 11 | AC_CHECK_FUNCS_ONCE([__fpurge]) |
| 12 | AC_CHECK_DECLS([fpurge], , , [[#include <stdio.h>]]) |
| 13 | if test "x$ac_cv_func_fpurge" = xyes; then |
| 14 | HAVE_FPURGE=1 |
| 15 | # Detect BSD bug. Only cygwin 1.7 is known to be immune. |
| 16 | AC_CACHE_CHECK([whether fpurge works], [gl_cv_func_fpurge_works], |
| 17 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h> |
| 18 | ]], [FILE *f = fopen ("conftest.txt", "w+"); |
| 19 | if (!f) return 1; |
| 20 | if (fputc ('a', f) != 'a') return 2; |
| 21 | rewind (f); |
| 22 | if (fgetc (f) != 'a') return 3; |
| 23 | if (fgetc (f) != EOF) return 4; |
| 24 | if (fpurge (f) != 0) return 5; |
| 25 | if (putc ('b', f) != 'b') return 6; |
| 26 | if (fclose (f) != 0) return 7; |
| 27 | if ((f = fopen ("conftest.txt", "r")) == NULL) return 8; |
| 28 | if (fgetc (f) != 'a') return 9; |
| 29 | if (fgetc (f) != 'b') return 10; |
| 30 | if (fgetc (f) != EOF) return 11; |
| 31 | if (fclose (f) != 0) return 12; |
| 32 | if (remove ("conftest.txt") != 0) return 13; |
| 33 | return 0;])], |
| 34 | [gl_cv_func_fpurge_works=yes], [gl_cv_func_fpurge_works=no], |
| 35 | [gl_cv_func_fpurge_works='guessing no'])]) |
| 36 | if test "x$gl_cv_func_fpurge_works" != xyes; then |
| 37 | REPLACE_FPURGE=1 |
| 38 | fi |
| 39 | else |
| 40 | HAVE_FPURGE=0 |
| 41 | fi |
| 42 | if test "x$ac_cv_have_decl_fpurge" = xno; then |
| 43 | HAVE_DECL_FPURGE=0 |
| 44 | fi |
| 45 | ]) |