| 1 |
# freopen.m4 |
| 2 |
# serial 8 |
| 3 |
dnl Copyright (C) 2007-2025 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_FREOPEN], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_STDIO_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 13 |
case "$host_os" in |
| 14 |
mingw* | windows* | pw* | os2*) |
| 15 |
REPLACE_FREOPEN=1 |
| 16 |
;; |
| 17 |
*) |
| 18 |
AC_CACHE_CHECK([whether freopen works on closed fds], |
| 19 |
[gl_cv_func_freopen_works_on_closed], |
| 20 |
[AC_RUN_IFELSE( |
| 21 |
[AC_LANG_PROGRAM( |
| 22 |
[[#include <stdio.h> |
| 23 |
#include <unistd.h> |
| 24 |
]GL_MDA_DEFINES], |
| 25 |
[[close (0); |
| 26 |
return !(freopen ("/dev/null", "r", stdin) |
| 27 |
&& getchar () == EOF |
| 28 |
&& !ferror (stdin) && feof (stdin));]])], |
| 29 |
[gl_cv_func_freopen_works_on_closed=yes], |
| 30 |
[gl_cv_func_freopen_works_on_closed=no], |
| 31 |
[case $host_os in |
| 32 |
*gnu*) gl_cv_func_freopen_works_on_closed="guessing no" ;; |
| 33 |
*) gl_cv_func_freopen_works_on_closed="guessing yes";; |
| 34 |
esac])]) |
| 35 |
case $gl_cv_func_freopen_works_on_closed in |
| 36 |
*no) REPLACE_FREOPEN=1;; |
| 37 |
esac |
| 38 |
esac |
| 39 |
]) |
| 40 |
|
| 41 |
# Prerequisites of lib/freopen.c. |
| 42 |
AC_DEFUN([gl_PREREQ_FREOPEN], [:]) |