File: fpurge.m4

package info (click to toggle)
datamash 1.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,600 kB
  • sloc: ansic: 65,320; sh: 8,982; perl: 5,127; makefile: 250; sed: 16
file content (74 lines) | stat: -rw-r--r-- 2,571 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# fpurge.m4
# serial 16
dnl Copyright (C) 2007, 2009-2025 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl This file is offered as-is, without any warranty.

AC_DEFUN([gl_FUNC_FPURGE],
[
  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
  AC_CHECK_HEADERS_ONCE([stdio_ext.h])
  AC_CHECK_FUNCS_ONCE([fpurge])
  gl_CHECK_FUNCS_ANDROID([__fpurge], [[#include <stdio_ext.h>]])
  AC_CHECK_DECLS([fpurge], , , [[#include <stdio.h>]])
  if test $ac_cv_func_fpurge = yes; then
    HAVE_FPURGE=1
    # Detect BSD bug.  Only cygwin 1.7 and musl are known to be immune.
    AC_CACHE_CHECK([whether fpurge works], [gl_cv_func_fpurge_works],
      [if test $ac_cv_have_decl_fpurge = yes; then
         AC_RUN_IFELSE(
           [AC_LANG_PROGRAM(
              [[#include <stdio.h>
              ]],
              [[FILE *f = fopen ("conftest.txt", "w+");
                if (!f)
                  return 1;
                if (fputc ('a', f) != 'a')
                  { fclose (f); return 2; }
                rewind (f);
                if (fgetc (f) != 'a')
                  { fclose (f); return 3; }
                if (fgetc (f) != EOF)
                  { fclose (f); return 4; }
                if (fpurge (f) != 0)
                  { fclose (f); return 5; }
                if (putc ('b', f) != 'b')
                  { fclose (f); return 6; }
                if (fclose (f) != 0)
                  return 7;
                if ((f = fopen ("conftest.txt", "r")) == NULL)
                  return 8;
                if (fgetc (f) != 'a')
                  { fclose (f); return 9; }
                if (fgetc (f) != 'b')
                  { fclose (f); return 10; }
                if (fgetc (f) != EOF)
                  { fclose (f); return 11; }
                if (fclose (f) != 0)
                  return 12;
                if (remove ("conftest.txt") != 0)
                  return 13;
                return 0;
              ]])],
           [gl_cv_func_fpurge_works=yes],
           [gl_cv_func_fpurge_works=no],
           [# Obey --enable-cross-guesses.
            gl_cv_func_fpurge_works="$gl_cross_guess_normal"
           ])
       else
         gl_cv_func_fpurge_works=no
       fi
      ])
    case "$gl_cv_func_fpurge_works" in
      *yes) ;;
      *) REPLACE_FPURGE=1 ;;
    esac
  else
    HAVE_FPURGE=0
  fi
  if test "x$ac_cv_have_decl_fpurge" = xno; then
    HAVE_DECL_FPURGE=0
  fi
])