1# fpurge.m4 serial 8 2dnl Copyright (C) 2007, 2009-2018 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7AC_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( 18 [AC_LANG_PROGRAM( 19 [[#include <stdio.h> 20]], 21 [FILE *f = fopen ("conftest.txt", "w+"); 22 if (!f) 23 return 1; 24 if (fputc ('a', f) != 'a') 25 { fclose (f); return 2; } 26 rewind (f); 27 if (fgetc (f) != 'a') 28 { fclose (f); return 3; } 29 if (fgetc (f) != EOF) 30 { fclose (f); return 4; } 31 if (fpurge (f) != 0) 32 { fclose (f); return 5; } 33 if (putc ('b', f) != 'b') 34 { fclose (f); return 6; } 35 if (fclose (f) != 0) 36 return 7; 37 if ((f = fopen ("conftest.txt", "r")) == NULL) 38 return 8; 39 if (fgetc (f) != 'a') 40 { fclose (f); return 9; } 41 if (fgetc (f) != 'b') 42 { fclose (f); return 10; } 43 if (fgetc (f) != EOF) 44 { fclose (f); return 11; } 45 if (fclose (f) != 0) 46 return 12; 47 if (remove ("conftest.txt") != 0) 48 return 13; 49 return 0; 50 ])], 51 [gl_cv_func_fpurge_works=yes], [gl_cv_func_fpurge_works=no], 52 [gl_cv_func_fpurge_works='guessing no'])]) 53 if test "x$gl_cv_func_fpurge_works" != xyes; then 54 REPLACE_FPURGE=1 55 fi 56 else 57 HAVE_FPURGE=0 58 fi 59 if test "x$ac_cv_have_decl_fpurge" = xno; then 60 HAVE_DECL_FPURGE=0 61 fi 62]) 63