| 1 |
# fopen.m4 |
| 2 |
# serial 16 |
| 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. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_FOPEN_ITSELF], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_STDIO_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 13 |
case "$host_os" in |
| 14 |
mingw* | windows* | pw*) |
| 15 |
dnl Replace fopen, for handling of "/dev/null". |
| 16 |
REPLACE_FOPEN=1 |
| 17 |
dnl fopen on mingw also has the trailing slash bug. |
| 18 |
gl_cv_func_fopen_slash="guessing no" |
| 19 |
;; |
| 20 |
*) |
| 21 |
dnl fopen("foo/", "w") should not create a file when the file name has a |
| 22 |
dnl trailing slash. |
| 23 |
AC_CACHE_CHECK([whether fopen recognizes a trailing slash], |
| 24 |
[gl_cv_func_fopen_slash], |
| 25 |
[ |
| 26 |
AC_RUN_IFELSE( |
| 27 |
[AC_LANG_SOURCE([[ |
| 28 |
#include <stddef.h> |
| 29 |
#include <stdio.h> |
| 30 |
int main () |
| 31 |
{ |
| 32 |
FILE *fp = fopen ("conftest.sl/", "w"); |
| 33 |
int result = (fp != NULL); |
| 34 |
if (fp != NULL) |
| 35 |
fclose (fp); |
| 36 |
return result; |
| 37 |
}]])], |
| 38 |
[gl_cv_func_fopen_slash=yes], |
| 39 |
[gl_cv_func_fopen_slash=no], |
| 40 |
[ |
| 41 |
changequote(,)dnl |
| 42 |
case "$host_os" in |
| 43 |
aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*) |
| 44 |
gl_cv_func_fopen_slash="guessing no" ;; |
| 45 |
*) |
| 46 |
gl_cv_func_fopen_slash="guessing yes" ;; |
| 47 |
esac |
| 48 |
changequote([,])dnl |
| 49 |
]) |
| 50 |
rm -f conftest.sl |
| 51 |
]) |
| 52 |
;; |
| 53 |
esac |
| 54 |
case "$gl_cv_func_fopen_slash" in |
| 55 |
*no) |
| 56 |
AC_DEFINE([FOPEN_TRAILING_SLASH_BUG], [1], |
| 57 |
[Define to 1 if fopen() fails to recognize a trailing slash.]) |
| 58 |
REPLACE_FOPEN=1 |
| 59 |
;; |
| 60 |
esac |
| 61 |
]) |
| 62 |
|
| 63 |
AC_DEFUN([gl_FUNC_FOPEN], |
| 64 |
[ |
| 65 |
AC_REQUIRE([gl_FUNC_FOPEN_ITSELF]) |
| 66 |
AC_REQUIRE([gl_FUNC_FCLOSE]) |
| 67 |
if test $REPLACE_FCLOSE = 1; then |
| 68 |
REPLACE_FOPEN=1 |
| 69 |
fi |
| 70 |
]) |
| 71 |
|
| 72 |
AC_DEFUN([gl_FUNC_FOPEN_GNU], |
| 73 |
[ |
| 74 |
AC_REQUIRE([gl_FUNC_FOPEN]) |
| 75 |
AC_CACHE_CHECK([whether fopen supports the mode character 'x'], |
| 76 |
[gl_cv_func_fopen_mode_x], |
| 77 |
[rm -f conftest.x |
| 78 |
AC_RUN_IFELSE( |
| 79 |
[AC_LANG_SOURCE([[ |
| 80 |
#include <stdio.h> |
| 81 |
#include <errno.h> |
| 82 |
int main () |
| 83 |
{ |
| 84 |
FILE *fp; |
| 85 |
fp = fopen ("conftest.x", "w"); |
| 86 |
fclose (fp); |
| 87 |
fp = fopen ("conftest.x", "wx"); |
| 88 |
if (fp != NULL) |
| 89 |
/* 'x' ignored */ |
| 90 |
return 1; |
| 91 |
else if (errno == EEXIST) |
| 92 |
return 0; |
| 93 |
else |
| 94 |
/* 'x' rejected */ |
| 95 |
return 2; |
| 96 |
}]])], |
| 97 |
[gl_cv_func_fopen_mode_x=yes], |
| 98 |
[gl_cv_func_fopen_mode_x=no], |
| 99 |
[case "$host_os" in |
| 100 |
# Guess yes on glibc and musl systems. |
| 101 |
linux*-gnu* | gnu* | kfreebsd*-gnu | *-musl* | midipix*) |
| 102 |
gl_cv_func_fopen_mode_x="guessing yes" ;; |
| 103 |
# If we don't know, obey --enable-cross-guesses. |
| 104 |
*) |
| 105 |
gl_cv_func_fopen_mode_x="$gl_cross_guess_normal" ;; |
| 106 |
esac |
| 107 |
]) |
| 108 |
rm -f conftest.x |
| 109 |
]) |
| 110 |
AC_CACHE_CHECK([whether fopen supports the mode character 'e'], |
| 111 |
[gl_cv_func_fopen_mode_e], |
| 112 |
[echo foo > conftest.x |
| 113 |
AC_RUN_IFELSE( |
| 114 |
[AC_LANG_SOURCE([[ |
| 115 |
#include <stdio.h> |
| 116 |
#include <errno.h> |
| 117 |
#include <fcntl.h> |
| 118 |
]GL_MDA_DEFINES[ |
| 119 |
int main () |
| 120 |
{ |
| 121 |
FILE *fp = fopen ("conftest.x", "re"); |
| 122 |
if (fp != NULL) |
| 123 |
{ |
| 124 |
if (fcntl (fileno (fp), F_GETFD) & FD_CLOEXEC) |
| 125 |
return 0; |
| 126 |
else |
| 127 |
/* 'e' ignored */ |
| 128 |
return 1; |
| 129 |
} |
| 130 |
else |
| 131 |
/* 'e' rejected */ |
| 132 |
return 2; |
| 133 |
}]])], |
| 134 |
[gl_cv_func_fopen_mode_e=yes], |
| 135 |
[gl_cv_func_fopen_mode_e=no], |
| 136 |
[case "$host_os" in |
| 137 |
# Guess yes on glibc and musl systems. |
| 138 |
linux*-gnu* | gnu* | kfreebsd*-gnu | *-musl* | midipix*) |
| 139 |
gl_cv_func_fopen_mode_e="guessing yes" ;; |
| 140 |
# Guess no on native Windows. |
| 141 |
mingw* | windows*) |
| 142 |
gl_cv_func_fopen_mode_e="guessing no" ;; |
| 143 |
# If we don't know, obey --enable-cross-guesses. |
| 144 |
*) |
| 145 |
gl_cv_func_fopen_mode_e="$gl_cross_guess_normal" ;; |
| 146 |
esac |
| 147 |
]) |
| 148 |
rm -f conftest.x |
| 149 |
]) |
| 150 |
REPLACE_FOPEN_FOR_FOPEN_GNU="$REPLACE_FOPEN" |
| 151 |
case "$gl_cv_func_fopen_mode_x" in |
| 152 |
*no) REPLACE_FOPEN_FOR_FOPEN_GNU=1 ;; |
| 153 |
esac |
| 154 |
case "$gl_cv_func_fopen_mode_e" in |
| 155 |
*no) REPLACE_FOPEN_FOR_FOPEN_GNU=1 ;; |
| 156 |
esac |
| 157 |
]) |
| 158 |
|
| 159 |
# Prerequisites of lib/fopen.c. |
| 160 |
AC_DEFUN([gl_PREREQ_FOPEN], [:]) |