ttyname_r: Make it work on MacOS X 10.4 and Solaris 10.
[pspp] / m4 / ttyname_r.m4
1 # ttyname_r.m4 serial 2
2 dnl Copyright (C) 2010 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_TTYNAME_R],
8 [
9   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10
11   AC_CHECK_FUNCS([ttyname_r])
12   if test $ac_cv_func_ttyname_r = no; then
13     HAVE_TTYNAME_R=0
14   else
15     dnl On MacOS X 10.4 and Solaris 10 the return type is 'char *', not 'int'.
16     AC_CACHE_CHECK([whether ttyname_r is compatible with its POSIX signature],
17       [gl_cv_func_ttyname_r_posix],
18       [AC_COMPILE_IFELSE(
19          [AC_LANG_PROGRAM(
20             [[#include <stddef.h>
21               #include <unistd.h>]],
22             [[*ttyname_r (0, NULL, 0);]])
23          ],
24          [gl_cv_func_ttyname_r_posix=no],
25          [gl_cv_func_ttyname_r_posix=yes])
26       ])
27     if test $gl_cv_func_ttyname_r_posix = no; then
28       REPLACE_TTYNAME_R=1
29     fi
30   fi
31   if test $HAVE_TTYNAME_R = 0 || test $REPLACE_TTYNAME_R = 1; then
32     AC_LIBOBJ([ttyname_r])
33     gl_PREREQ_TTYNAME_R
34   fi
35 ])
36
37 # Prerequisites of lib/ttyname_r.c.
38 AC_DEFUN([gl_PREREQ_TTYNAME_R], [
39   AC_CHECK_FUNCS([ttyname])
40 ])