ext/posix: posix_isatty set errno for it too.

Close GH-13918
This commit is contained in:
David Carlier 2024-04-08 22:26:14 +01:00
parent 2079da0158
commit db2869346c
No known key found for this signature in database
GPG Key ID: CEF290BB40D2086B
4 changed files with 14 additions and 0 deletions

2
NEWS
View File

@ -173,6 +173,8 @@ PHP NEWS
- POSIX:
. Added POSIX_SC_CHILD_MAX and POSIX_SC_CLK_TCK constants. (Jakub Zelenka)
. Updated posix_isatty to set the error number on file descriptors.
(David Carlier)
- PSpell:
. Moved to PECL. (Derick Rethans)

View File

@ -383,6 +383,10 @@ PHP 8.4 UPGRADE NOTES
- PGSQL:
. pg_select, the conditions arguments accepts an empty array and is optional.
- POSIX:
. posix_isatty now sets the error number when the file descriptor/stream argument
is invalid.
- SPL:
. SplPriorityQueue::insert() and SplPriorityQueue::recoverFromCorruption()
now has a tentative return type of true

View File

@ -521,11 +521,13 @@ PHP_FUNCTION(posix_isatty)
/* A valid file descriptor must fit in an int and be positive */
if (fd < 0 || fd > INT_MAX) {
POSIX_G(last_error) = EBADF;
RETURN_FALSE;
}
if (isatty(fd)) {
RETURN_TRUE;
} else {
POSIX_G(last_error) = errno;
RETURN_FALSE;
}
}

View File

@ -11,13 +11,19 @@ if (PHP_INT_SIZE != 8) die('skip C int is same size as zend_long');
$values = [
-1,
10024,
2**50+1,
];
foreach ($values as $value) {
var_dump(posix_isatty($value));
var_dump(posix_strerror(posix_get_last_error()));
}
?>
--EXPECT--
bool(false)
string(19) "Bad file descriptor"
bool(false)
string(19) "Bad file descriptor"
bool(false)
string(19) "Bad file descriptor"