From: Sara Golemon Date: Fri, 5 Jan 2007 21:30:06 +0000 (+0000) Subject: Refix posix_ttyname(), test for a working implementation of ttyname_r() -- which... X-Git-Tag: RELEASE_1_0_0RC1~386 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b42c175d7575ec889bbfcd7674fe1e31dbe74ff8;p=php Refix posix_ttyname(), test for a working implementation of ttyname_r() -- which BSD doesn't have --- diff --git a/ext/posix/config.m4 b/ext/posix/config.m4 index 9038330bb1..f84facde60 100644 --- a/ext/posix/config.m4 +++ b/ext/posix/config.m4 @@ -11,5 +11,22 @@ if test "$PHP_POSIX" = "yes"; then AC_CHECK_HEADERS(sys/mkdev.h) - AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo mknod getrlimit getlogin getgroups makedev initgroups getpwuid_r getgrgid_r ttyname_r) + AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo mknod getrlimit getlogin getgroups makedev initgroups getpwuid_r getgrgid_r) + + AC_MSG_CHECKING([for working ttyname_r() implementation]) + AC_TRY_RUN([ +#include + +int main(int argc, char *argv[]) +{ + char buf[64]; + + return ttyname_r(0, buf, 64) ? 1 : 0; +} + ],[ + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_TTYNAME_R, 1, [Whether you have a working ttyname_r]) + ],[ + AC_MSG_RESULT([no, posix_ttyname() will be thread-unsafe]) + ]) fi diff --git a/ext/posix/posix.c b/ext/posix/posix.c index e9bfd1da66..7809e48bf5 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -575,12 +575,7 @@ PHP_FUNCTION(posix_ttyname) fd = Z_LVAL_PP(z_fd); } #if HAVE_TTYNAME_R -#ifdef _SC_TTY_NAME_MAX buflen = sysconf(_SC_TTY_NAME_MAX); -#else - /* Arbitrary buffer size for systems which don't extrospect their tty name lengths, way overkill */ - buflen = 64; -#endif p = emalloc(buflen); if (ttyname_r(fd, p, buflen)) {