3 dnl Copyright (C) 2007-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([gl_FUNC_FOPEN_ITSELF],
10 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
11 AC_REQUIRE([AC_CANONICAL_HOST])
13 mingw* | windows* | pw*)
14 dnl Replace fopen, for handling of "/dev/null".
16 dnl fopen on mingw also has the trailing slash bug.
17 gl_cv_func_fopen_slash="guessing no"
20 dnl fopen("foo/", "w") should not create a file when the file name has a
22 AC_CACHE_CHECK([whether fopen recognizes a trailing slash],
23 [gl_cv_func_fopen_slash],
31 FILE *fp = fopen ("conftest.sl/", "w");
32 int result = (fp != NULL);
37 [gl_cv_func_fopen_slash=yes],
38 [gl_cv_func_fopen_slash=no],
42 aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*)
43 gl_cv_func_fopen_slash="guessing no" ;;
45 gl_cv_func_fopen_slash="guessing yes" ;;
53 case "$gl_cv_func_fopen_slash" in
55 AC_DEFINE([FOPEN_TRAILING_SLASH_BUG], [1],
56 [Define to 1 if fopen() fails to recognize a trailing slash.])
62 AC_DEFUN([gl_FUNC_FOPEN],
64 AC_REQUIRE([gl_FUNC_FOPEN_ITSELF])
65 AC_REQUIRE([gl_FUNC_FCLOSE])
66 if test $REPLACE_FCLOSE = 1; then
71 AC_DEFUN([gl_FUNC_FOPEN_GNU],
73 AC_REQUIRE([gl_FUNC_FOPEN])
74 AC_CACHE_CHECK([whether fopen supports the mode character 'x'],
75 [gl_cv_func_fopen_mode_x],
84 fp = fopen ("conftest.x", "w");
86 fp = fopen ("conftest.x", "wx");
90 else if (errno == EEXIST)
96 [gl_cv_func_fopen_mode_x=yes],
97 [gl_cv_func_fopen_mode_x=no],
99 # Guess yes on glibc and musl systems.
100 linux*-gnu* | gnu* | kfreebsd*-gnu | *-musl* | midipix*)
101 gl_cv_func_fopen_mode_x="guessing yes" ;;
102 # If we don't know, obey --enable-cross-guesses.
104 gl_cv_func_fopen_mode_x="$gl_cross_guess_normal" ;;
109 AC_CACHE_CHECK([whether fopen supports the mode character 'e'],
110 [gl_cv_func_fopen_mode_e],
111 [echo foo > conftest.x
120 FILE *fp = fopen ("conftest.x", "re");
123 if (fcntl (fileno (fp), F_GETFD) & FD_CLOEXEC)
133 [gl_cv_func_fopen_mode_e=yes],
134 [gl_cv_func_fopen_mode_e=no],
136 # Guess yes on glibc and musl systems.
137 linux*-gnu* | gnu* | kfreebsd*-gnu | *-musl* | midipix*)
138 gl_cv_func_fopen_mode_e="guessing yes" ;;
139 # Guess no on native Windows.
141 gl_cv_func_fopen_mode_e="guessing no" ;;
142 # If we don't know, obey --enable-cross-guesses.
144 gl_cv_func_fopen_mode_e="$gl_cross_guess_normal" ;;
149 REPLACE_FOPEN_FOR_FOPEN_GNU="$REPLACE_FOPEN"
150 case "$gl_cv_func_fopen_mode_x" in
151 *no) REPLACE_FOPEN_FOR_FOPEN_GNU=1 ;;
153 case "$gl_cv_func_fopen_mode_e" in
154 *no) REPLACE_FOPEN_FOR_FOPEN_GNU=1 ;;
158 # Prerequisites of lib/fopen.c.
159 AC_DEFUN([gl_PREREQ_FOPEN], [:])