3 dnl Copyright (C) 2008-2024 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.
8 AC_DEFUN_ONCE([gl_FUNC_FCLOSE],
10 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
11 AC_REQUIRE([AC_CANONICAL_HOST])
14 case "$gl_cv_func_fflush_stdin" in
16 *) REPLACE_FCLOSE=1 ;;
19 AC_REQUIRE([gl_FUNC_CLOSE])
20 if test $REPLACE_CLOSE = 1; then
25 openedition) REPLACE_FCLOSE=1 ;;
28 if test $REPLACE_FCLOSE = 0; then
30 case "$gl_cv_func_fclose_stdin" in
32 *) REPLACE_FCLOSE=1 ;;
37 dnl Determine whether fclose works on input streams.
38 dnl Sets gl_cv_func_fclose_stdin.
40 AC_DEFUN([gl_FUNC_FCLOSE_STDIN],
42 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
43 AC_CHECK_HEADERS_ONCE([unistd.h])
44 AC_CACHE_CHECK([whether fclose works on input streams],
45 [gl_cv_func_fclose_stdin],
46 [echo hello world > conftest.txt
53 #else /* on Windows with MSVC */
60 fd = open ("conftest.txt", O_RDONLY);
63 if (lseek (fd, 1, SEEK_SET) != 1)
68 fp = fdopen (fd2, "r");
71 if (fgetc (fp) != 'e')
72 { fclose (fp); return 5; }
73 /* This fclose() call should reposition the underlying file
77 if (lseek (fd2, 0, SEEK_CUR) != -1) /* should fail with EBADF */
79 /* Verify the file position. */
80 if (lseek (fd, 0, SEEK_CUR) != 2)
84 [gl_cv_func_fclose_stdin=yes],
85 [gl_cv_func_fclose_stdin=no],
87 # Guess no on glibc systems.
88 *-gnu* | gnu*) gl_cv_func_fclose_stdin="guessing no" ;;
89 # Guess yes on musl systems.
90 *-musl* | midipix*) gl_cv_func_fclose_stdin="guessing yes" ;;
91 # Guess no on native Windows.
92 mingw* | windows*) gl_cv_func_fclose_stdin="guessing no" ;;
93 # If we don't know, obey --enable-cross-guesses.
94 *) gl_cv_func_fclose_stdin="$gl_cross_guess_normal" ;;