| 1 | # fopen.m4 serial 12
|
|---|
| 2 | dnl Copyright (C) 2007-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.
|
|---|
| 6 |
|
|---|
| 7 | AC_DEFUN([gl_FUNC_FOPEN],
|
|---|
| 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_GNU],
|
|---|
| 62 | [
|
|---|
| 63 | AC_REQUIRE([gl_FUNC_FOPEN])
|
|---|
| 64 | AC_CACHE_CHECK([whether fopen supports the mode character 'x'],
|
|---|
| 65 | [gl_cv_func_fopen_mode_x],
|
|---|
| 66 | [rm -f conftest.x
|
|---|
| 67 | AC_RUN_IFELSE(
|
|---|
| 68 | [AC_LANG_SOURCE([[
|
|---|
| 69 | #include <stdio.h>
|
|---|
| 70 | #include <errno.h>
|
|---|
| 71 | int main ()
|
|---|
| 72 | {
|
|---|
| 73 | FILE *fp;
|
|---|
| 74 | fp = fopen ("conftest.x", "w");
|
|---|
| 75 | fclose (fp);
|
|---|
| 76 | fp = fopen ("conftest.x", "wx");
|
|---|
| 77 | if (fp != NULL)
|
|---|
| 78 | /* 'x' ignored */
|
|---|
| 79 | return 1;
|
|---|
| 80 | else if (errno == EEXIST)
|
|---|
| 81 | return 0;
|
|---|
| 82 | else
|
|---|
| 83 | /* 'x' rejected */
|
|---|
| 84 | return 2;
|
|---|
| 85 | }]])],
|
|---|
| 86 | [gl_cv_func_fopen_mode_x=yes],
|
|---|
| 87 | [gl_cv_func_fopen_mode_x=no],
|
|---|
| 88 | [case "$host_os" in
|
|---|
| 89 | # Guess yes on glibc and musl systems.
|
|---|
| 90 | linux*-gnu* | gnu* | kfreebsd*-gnu | *-musl*)
|
|---|
| 91 | gl_cv_func_fopen_mode_x="guessing yes" ;;
|
|---|
| 92 | # If we don't know, obey --enable-cross-guesses.
|
|---|
| 93 | *)
|
|---|
| 94 | gl_cv_func_fopen_mode_x="$gl_cross_guess_normal" ;;
|
|---|
| 95 | esac
|
|---|
| 96 | ])
|
|---|
| 97 | rm -f conftest.x
|
|---|
| 98 | ])
|
|---|
| 99 | AC_CACHE_CHECK([whether fopen supports the mode character 'e'],
|
|---|
| 100 | [gl_cv_func_fopen_mode_e],
|
|---|
| 101 | [echo foo > conftest.x
|
|---|
| 102 | AC_RUN_IFELSE(
|
|---|
| 103 | [AC_LANG_SOURCE([[
|
|---|
| 104 | #include <stdio.h>
|
|---|
| 105 | #include <errno.h>
|
|---|
| 106 | #include <fcntl.h>
|
|---|
| 107 | ]GL_MDA_DEFINES[
|
|---|
| 108 | int main ()
|
|---|
| 109 | {
|
|---|
| 110 | FILE *fp = fopen ("conftest.x", "re");
|
|---|
| 111 | if (fp != NULL)
|
|---|
| 112 | {
|
|---|
| 113 | if (fcntl (fileno (fp), F_GETFD) & FD_CLOEXEC)
|
|---|
| 114 | return 0;
|
|---|
| 115 | else
|
|---|
| 116 | /* 'e' ignored */
|
|---|
| 117 | return 1;
|
|---|
| 118 | }
|
|---|
| 119 | else
|
|---|
| 120 | /* 'e' rejected */
|
|---|
| 121 | return 2;
|
|---|
| 122 | }]])],
|
|---|
| 123 | [gl_cv_func_fopen_mode_e=yes],
|
|---|
| 124 | [gl_cv_func_fopen_mode_e=no],
|
|---|
| 125 | [case "$host_os" in
|
|---|
| 126 | # Guess yes on glibc and musl systems.
|
|---|
| 127 | linux*-gnu* | gnu* | kfreebsd*-gnu | *-musl*)
|
|---|
| 128 | gl_cv_func_fopen_mode_e="guessing yes" ;;
|
|---|
| 129 | # Guess no on native Windows.
|
|---|
| 130 | mingw*)
|
|---|
| 131 | gl_cv_func_fopen_mode_e="guessing no" ;;
|
|---|
| 132 | # If we don't know, obey --enable-cross-guesses.
|
|---|
| 133 | *)
|
|---|
| 134 | gl_cv_func_fopen_mode_e="$gl_cross_guess_normal" ;;
|
|---|
| 135 | esac
|
|---|
| 136 | ])
|
|---|
| 137 | rm -f conftest.x
|
|---|
| 138 | ])
|
|---|
| 139 | case "$gl_cv_func_fopen_mode_x" in
|
|---|
| 140 | *no) REPLACE_FOPEN=1 ;;
|
|---|
| 141 | esac
|
|---|
| 142 | case "$gl_cv_func_fopen_mode_e" in
|
|---|
| 143 | *no) REPLACE_FOPEN=1 ;;
|
|---|
| 144 | esac
|
|---|
| 145 | ])
|
|---|
| 146 |
|
|---|
| 147 | # Prerequisites of lib/fopen.c.
|
|---|
| 148 | AC_DEFUN([gl_PREREQ_FOPEN], [:])
|
|---|