| 
1 | 1 | #[=============================================================================[  | 
2 |  | -Check ttyname_r().  | 
3 |  | -
  | 
 | 2 | +This check determines whether the ttyname_r() is present and works as expected.  | 
4 | 3 | On Solaris/illumos ttyname_r() works only with larger buffers (>= 128), unlike,  | 
5 |  | -for example, on Linux and other systems, where buffer size can be any  | 
6 |  | -'size_t' size, also < 128. PHP code uses ttyname_r() with large buffers, so it  | 
7 |  | -wouldn't be necessary to check small buffers but the run check below is kept for  | 
8 |  | -brevity.  | 
 | 4 | +for example, on Linux and other systems, where buffer size can be any 'size_t'  | 
 | 5 | +size, also < 128. PHP code uses ttyname_r() with large buffers, so it wouldn't  | 
 | 6 | +be necessary to check small buffers but the run check below is kept for brevity.  | 
9 | 7 | 
  | 
10 | 8 | On modern systems a simpler check is sufficient in the future:  | 
11 | 9 | 
  | 
12 |  | -  check_symbol_exists(ttyname_r unistd.h HAVE_TTYNAME_R)  | 
13 |  | -
  | 
14 |  | -Result variables:  | 
15 |  | -
  | 
16 |  | -* HAVE_TTYNAME_R - Whether ttyname_r() works as expected.  | 
 | 10 | +  check_symbol_exists(ttyname_r unistd.h <result-var>)  | 
17 | 11 | #]=============================================================================]  | 
18 | 12 | 
 
  | 
19 |  | -include_guard(GLOBAL)  | 
20 |  | - | 
21 | 13 | include(CheckPrototypeDefinition)  | 
22 | 14 | include(CheckSourceRuns)  | 
23 | 15 | include(CMakePushCheckState)  | 
24 | 16 | include(PHP/SystemExtensions)  | 
25 | 17 | 
 
  | 
26 |  | -set(HAVE_TTYNAME_R FALSE)  | 
 | 18 | +function(_php_ext_posix_check_ttyname_r result)  | 
 | 19 | +  set(${result} FALSE)  | 
27 | 20 | 
 
  | 
28 |  | -# Skip in consecutive configuration phases.  | 
29 |  | -if(  | 
30 |  | -  DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R_PROTOTYPE  | 
31 |  | -  OR DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R  | 
32 |  | -)  | 
33 | 21 |   if(PHP_EXT_POSIX_HAS_TTYNAME_R)  | 
34 |  | -    set(HAVE_TTYNAME_R TRUE)  | 
35 |  | -  endif()  | 
36 |  | - | 
37 |  | -  return()  | 
38 |  | -endif()  | 
39 |  | - | 
40 |  | -message(CHECK_START "Checking for working ttyname_r()")  | 
41 |  | - | 
42 |  | -cmake_push_check_state(RESET)  | 
43 |  | -  cmake_language(GET_MESSAGE_LOG_LEVEL log_level)  | 
44 |  | -  if(NOT log_level MATCHES "^(VERBOSE|DEBUG|TRACE)$")  | 
45 |  | -    set(CMAKE_REQUIRED_QUIET TRUE)  | 
46 |  | -  endif()  | 
47 |  | - | 
48 |  | -  # To get the standard declaration with return type int instead of the char *:  | 
49 |  | -  # - _POSIX_PTHREAD_SEMANTICS is needed on Solaris<=11.3 and illumos  | 
50 |  | -  # - _DARWIN_C_SOURCE on older Mac OS X 10.4  | 
51 |  | -  set(CMAKE_REQUIRED_LIBRARIES PHP::SystemExtensions)  | 
52 |  | - | 
53 |  | -  check_prototype_definition(  | 
54 |  | -    ttyname_r  | 
55 |  | -    "int ttyname_r(int fd, char *buf, size_t buflen)"  | 
56 |  | -    "0"  | 
57 |  | -    "unistd.h"  | 
58 |  | -    PHP_EXT_POSIX_HAS_TTYNAME_R_PROTOTYPE  | 
59 |  | -  )  | 
60 |  | - | 
61 |  | -  if(NOT PHP_EXT_POSIX_HAS_TTYNAME_R_PROTOTYPE)  | 
62 |  | -    message(CHECK_FAIL "no (non-standard declaration)")  | 
63 |  | -    cmake_pop_check_state()  | 
64 |  | -    return()  | 
 | 22 | +    set(${result} TRUE)  | 
 | 23 | +    return(PROPAGATE ${result})  | 
65 | 24 |   endif()  | 
66 | 25 | 
 
  | 
67 |  | -  if(  | 
68 |  | -    CMAKE_CROSSCOMPILING  | 
69 |  | -    AND NOT CMAKE_CROSSCOMPILING_EMULATOR  | 
70 |  | -    AND NOT DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R_EXITCODE  | 
71 |  | -  )  | 
72 |  | -    set(PHP_EXT_POSIX_HAS_TTYNAME_R_EXITCODE 0)  | 
 | 26 | +  if(DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R_SYMBOL)  | 
 | 27 | +    return(PROPAGATE ${result})  | 
73 | 28 |   endif()  | 
74 | 29 | 
 
  | 
75 |  | -  # PHP Autotools-based build system check uses a different return below due  | 
76 |  | -  # to Autoconf's configure using the file descriptor 0 which results in an  | 
77 |  | -  # error. The file descriptor 0 with CMake script execution is available and  | 
78 |  | -  # doesn't result in an error when calling ttyname_r().  | 
79 |  | -  check_source_runs(C [[  | 
80 |  | -    #include <unistd.h>  | 
81 |  | - | 
82 |  | -    int main(void)  | 
83 |  | -    {  | 
84 |  | -      #ifdef _SC_TTY_NAME_MAX  | 
85 |  | -        int buflen = sysconf(_SC_TTY_NAME_MAX);  | 
86 |  | -      #else  | 
87 |  | -        int buflen = 32; /* Small buffers < 128 */  | 
88 |  | -      #endif  | 
89 |  | -      if (buflen < 1) {  | 
90 |  | -        buflen = 32;  | 
 | 30 | +  message(CHECK_START "Checking for working ttyname_r()")  | 
 | 31 | + | 
 | 32 | +  cmake_push_check_state(RESET)  | 
 | 33 | +    cmake_language(GET_MESSAGE_LOG_LEVEL log_level)  | 
 | 34 | +    if(NOT log_level MATCHES "^(VERBOSE|DEBUG|TRACE)$")  | 
 | 35 | +      set(CMAKE_REQUIRED_QUIET TRUE)  | 
 | 36 | +    endif()  | 
 | 37 | + | 
 | 38 | +    # To get the standard declaration with return type int instead of the  | 
 | 39 | +    # 'char *':  | 
 | 40 | +    # - _POSIX_PTHREAD_SEMANTICS is needed on Solaris<=11.3 and illumos  | 
 | 41 | +    # - _DARWIN_C_SOURCE on older Mac OS X 10.4  | 
 | 42 | +    set(CMAKE_REQUIRED_LIBRARIES PHP::SystemExtensions)  | 
 | 43 | + | 
 | 44 | +    check_prototype_definition(  | 
 | 45 | +      ttyname_r  | 
 | 46 | +      "int ttyname_r(int fd, char *buf, size_t buflen)"  | 
 | 47 | +      "0"  | 
 | 48 | +      "unistd.h"  | 
 | 49 | +      PHP_EXT_POSIX_HAS_TTYNAME_R_SYMBOL  | 
 | 50 | +    )  | 
 | 51 | + | 
 | 52 | +    if(NOT PHP_EXT_POSIX_HAS_TTYNAME_R_SYMBOL)  | 
 | 53 | +      message(CHECK_FAIL "no (non-standard declaration)")  | 
 | 54 | +      cmake_pop_check_state()  | 
 | 55 | +      return(PROPAGATE ${result})  | 
 | 56 | +    endif()  | 
 | 57 | + | 
 | 58 | +    if(  | 
 | 59 | +      CMAKE_CROSSCOMPILING  | 
 | 60 | +      AND NOT CMAKE_CROSSCOMPILING_EMULATOR  | 
 | 61 | +      AND NOT DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R_EXITCODE  | 
 | 62 | +    )  | 
 | 63 | +      set(PHP_EXT_POSIX_HAS_TTYNAME_R_EXITCODE 0)  | 
 | 64 | +    endif()  | 
 | 65 | + | 
 | 66 | +    # PHP Autotools-based build system check uses a different return below due  | 
 | 67 | +    # to Autoconf's configure using the file descriptor 0 which results in an  | 
 | 68 | +    # error. The file descriptor 0 with CMake script execution is available  | 
 | 69 | +    # and doesn't result in an error when calling ttyname_r().  | 
 | 70 | +    check_source_runs(C [[  | 
 | 71 | +      #include <unistd.h>  | 
 | 72 | + | 
 | 73 | +      int main(void)  | 
 | 74 | +      {  | 
 | 75 | +        #ifdef _SC_TTY_NAME_MAX  | 
 | 76 | +          int buflen = sysconf(_SC_TTY_NAME_MAX);  | 
 | 77 | +        #else  | 
 | 78 | +          int buflen = 32; /* Small buffers < 128 */  | 
 | 79 | +        #endif  | 
 | 80 | +        if (buflen < 1) {  | 
 | 81 | +          buflen = 32;  | 
 | 82 | +        }  | 
 | 83 | +        char buf[buflen];  | 
 | 84 | + | 
 | 85 | +        return ttyname_r(0, buf, buflen) ? 1 : 0;  | 
91 | 86 |       }  | 
92 |  | -      char buf[buflen];  | 
 | 87 | +    ]] PHP_EXT_POSIX_HAS_TTYNAME_R)  | 
 | 88 | +  cmake_pop_check_state()  | 
93 | 89 | 
 
  | 
94 |  | -      return ttyname_r(0, buf, buflen) ? 1 : 0;  | 
95 |  | -    }  | 
96 |  | -  ]] PHP_EXT_POSIX_HAS_TTYNAME_R)  | 
97 | 90 |   if(PHP_EXT_POSIX_HAS_TTYNAME_R)  | 
98 |  | -    set(HAVE_TTYNAME_R TRUE)  | 
 | 91 | +    set(${result} TRUE)  | 
99 | 92 |     message(CHECK_PASS "yes")  | 
100 | 93 |   else()  | 
101 | 94 |     message(CHECK_FAIL "no (posix_ttyname() will be thread-unsafe)")  | 
102 | 95 |   endif()  | 
103 |  | -cmake_pop_check_state()  | 
 | 96 | + | 
 | 97 | +  return(PROPAGATE ${result})  | 
 | 98 | +endfunction()  | 
 | 99 | + | 
 | 100 | +_php_ext_posix_check_ttyname_r(HAVE_TTYNAME_R)  | 
0 commit comments