| 1 |
# popen.m4 |
| 2 |
# serial 8 |
| 3 |
dnl Copyright (C) 2009-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_POPEN], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_STDIO_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 13 |
AC_CHECK_FUNCS_ONCE([popen]) |
| 14 |
if test $ac_cv_func_popen = no; then |
| 15 |
HAVE_POPEN=0 |
| 16 |
else |
| 17 |
AC_CACHE_CHECK([whether popen works with closed stdin], |
| 18 |
[gl_cv_func_popen_works], |
| 19 |
[ |
| 20 |
case "$host_os" in |
| 21 |
os2*) |
| 22 |
# On OS/2 kLIBC, popen() with closed stdios hangs on. |
| 23 |
gl_cv_func_popen_works="guessing no" |
| 24 |
;; |
| 25 |
*) |
| 26 |
AC_RUN_IFELSE( |
| 27 |
[AC_LANG_PROGRAM( |
| 28 |
[[#include <stdio.h>]], |
| 29 |
[[int result = 0; |
| 30 |
FILE *child; |
| 31 |
fclose (stdin); |
| 32 |
fclose (stdout); |
| 33 |
child = popen ("echo a", "r"); |
| 34 |
if (fgetc (child) != 'a') |
| 35 |
result |= 1; |
| 36 |
if (pclose (child) != 0) |
| 37 |
result |= 2; |
| 38 |
return result; |
| 39 |
]])], |
| 40 |
[gl_cv_func_popen_works=yes], |
| 41 |
[gl_cv_func_popen_works=no], |
| 42 |
[case "$host_os" in |
| 43 |
# For now, only cygwin 1.5 or older is known to be broken. |
| 44 |
cygwin*) gl_cv_func_popen_works="guessing no" ;; |
| 45 |
# Guess yes on native Windows. |
| 46 |
mingw* | windows*) gl_cv_func_popen_works="guessing yes" ;; |
| 47 |
*) gl_cv_func_popen_works="guessing yes" ;; |
| 48 |
esac |
| 49 |
]) |
| 50 |
;; |
| 51 |
esac |
| 52 |
]) |
| 53 |
case "$gl_cv_func_popen_works" in |
| 54 |
*yes) ;; |
| 55 |
*) REPLACE_POPEN=1 ;; |
| 56 |
esac |
| 57 |
fi |
| 58 |
]) |
| 59 |
|
| 60 |
# Prerequisites of lib/popen.c. |
| 61 |
AC_DEFUN([gl_PREREQ_POPEN], |
| 62 |
[ |
| 63 |
: |
| 64 |
]) |