Skip to content

Commit db28693

Browse files
committed
ext/posix: posix_isatty set errno for it too.
Close GH-13918
1 parent 2079da0 commit db28693

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ PHP NEWS
173173

174174
- POSIX:
175175
. Added POSIX_SC_CHILD_MAX and POSIX_SC_CLK_TCK constants. (Jakub Zelenka)
176+
. Updated posix_isatty to set the error number on file descriptors.
177+
(David Carlier)
176178

177179
- PSpell:
178180
. Moved to PECL. (Derick Rethans)

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ PHP 8.4 UPGRADE NOTES
383383
- PGSQL:
384384
. pg_select, the conditions arguments accepts an empty array and is optional.
385385

386+
- POSIX:
387+
. posix_isatty now sets the error number when the file descriptor/stream argument
388+
is invalid.
389+
386390
- SPL:
387391
. SplPriorityQueue::insert() and SplPriorityQueue::recoverFromCorruption()
388392
now has a tentative return type of true

ext/posix/posix.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,13 @@ PHP_FUNCTION(posix_isatty)
521521

522522
/* A valid file descriptor must fit in an int and be positive */
523523
if (fd < 0 || fd > INT_MAX) {
524+
POSIX_G(last_error) = EBADF;
524525
RETURN_FALSE;
525526
}
526527
if (isatty(fd)) {
527528
RETURN_TRUE;
528529
} else {
530+
POSIX_G(last_error) = errno;
529531
RETURN_FALSE;
530532
}
531533
}

ext/posix/tests/posix_isatty_value_errors.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@ if (PHP_INT_SIZE != 8) die('skip C int is same size as zend_long');
1111

1212
$values = [
1313
-1,
14+
10024,
1415
2**50+1,
1516
];
1617

1718
foreach ($values as $value) {
1819
var_dump(posix_isatty($value));
20+
var_dump(posix_strerror(posix_get_last_error()));
1921
}
2022
?>
2123
--EXPECT--
2224
bool(false)
25+
string(19) "Bad file descriptor"
2326
bool(false)
27+
string(19) "Bad file descriptor"
28+
bool(false)
29+
string(19) "Bad file descriptor"

0 commit comments

Comments
 (0)