2 dnl Copyright (C) 2008-2021 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.
7 AC_DEFUN([gl_FUNC_FCLOSE],
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST])
13 case "$gl_cv_func_fflush_stdin" in
15 *) REPLACE_FCLOSE=1 ;;
18 AC_REQUIRE([gl_FUNC_CLOSE])
19 if test $REPLACE_CLOSE = 1; then
24 openedition) REPLACE_FCLOSE=1 ;;
27 if test $REPLACE_FCLOSE = 0; then
29 case "$gl_cv_func_fclose_stdin" in
31 *) REPLACE_FCLOSE=1 ;;
36 dnl Determine whether fclose works on input streams.
37 dnl Sets gl_cv_func_fclose_stdin.
39 AC_DEFUN([gl_FUNC_FCLOSE_STDIN],
41 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
42 AC_CHECK_HEADERS_ONCE([unistd.h])
43 AC_CACHE_CHECK([whether fclose works on input streams],
44 [gl_cv_func_fclose_stdin],
45 [echo hello world > conftest.txt
52 #else /* on Windows with MSVC */
59 fd = open ("conftest.txt", O_RDONLY);
62 if (lseek (fd, 1, SEEK_SET) != 1)
67 fp = fdopen (fd2, "r");
70 if (fgetc (fp) != 'e')
71 { fclose (fp); return 5; }
72 /* This fclose() call should reposition the underlying file
76 if (lseek (fd2, 0, SEEK_CUR) != -1) /* should fail with EBADF */
78 /* Verify the file position. */
79 if (lseek (fd, 0, SEEK_CUR) != 2)
83 [gl_cv_func_fclose_stdin=yes],
84 [gl_cv_func_fclose_stdin=no],
86 # Guess no on glibc systems.
87 *-gnu* | gnu*) gl_cv_func_fclose_stdin="guessing no" ;;
88 # Guess yes on musl systems.
89 *-musl*) gl_cv_func_fclose_stdin="guessing yes" ;;
90 # Guess no on native Windows.
91 mingw*) gl_cv_func_fclose_stdin="guessing no" ;;
92 # If we don't know, obey --enable-cross-guesses.
93 *) gl_cv_func_fclose_stdin="$gl_cross_guess_normal" ;;