Debian Codegraph @

m4/fopen.m4

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