[php-src] master: ext/posix: posix_isatty set errno for it too.
| From: | David Carlier | Date: | Tue, 09 Apr 2024 16:34:34 +0000 |
| Subject: | [php-src] master: ext/posix: posix_isatty set errno for it too. | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-127997@lists.php.net to get a copy of this message | ||
Author: David Carlier (devnexen)
Date: 2024-04-09T17:34:03+01:00
Commit: https://github.com/php/php-src/commit/db2869346ce033a379c4d3440a7708465adbc8e1
Raw diff: https://github.com/php/php-src/commit/db2869346ce033a379c4d3440a7708465adbc8e1.diff
ext/posix: posix_isatty set errno for it too.
Close GH-13918
Changed paths:
M NEWS
M UPGRADING
M ext/posix/posix.c
M ext/posix/tests/posix_isatty_value_errors.phpt
Diff:
diff --git a/NEWS b/NEWS
index 84b3a976bd452..89d14dea9a0f0 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
diff --git a/UPGRADING b/UPGRADING
index eb4993b52815b..3450825a2a584 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -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
diff --git a/ext/posix/posix.c b/ext/posix/posix.c
index f6e028f9a96e3..787b18ae28126 100644
--- a/ext/posix/posix.c
+++ b/ext/posix/posix.c
@@ -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;
}
}
diff --git a/ext/posix/tests/posix_isatty_value_errors.phpt
b/ext/posix/tests/posix_isatty_value_errors.phpt
index 19dfe62c93019..e57564e7eacd7 100644
--- a/ext/posix/tests/posix_isatty_value_errors.phpt
+++ b/ext/posix/tests/posix_isatty_value_errors.phpt
@@ -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"