Skip to content

ext/posix: posix_isatty set errno for it too. #13918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 6 additions & 0 deletions ext/posix/tests/posix_isatty_value_errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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"