# [PATCH] Make streams respect POSIX error retrieval functions (bug #36868)

- Thread: https://externals.io/message/22592
- Original archive: https://news-web.php.net/php.internals/22592
- Started by Hannes Magnusson on 2006-03-27T11:23:39+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #22592 — Hannes Magnusson — 2006-03-27T11:23:39+00:00

URL: https://externals.io/message/22592#22592

Hi all

Attached is a patch (against HEAD) to allow codes like:
$fp = @fopen("/unwritabledirectory/filename", "w");
if (!$fp) {
printf("The errornr was: %d", `posix_get_last_error()`);
}

Fixes bug #36868

(If, for what ever reason, the patch doesn't come through:
http://php.is/bugs/36868/posix.patch.txt )
- Hannes

---

## #22593 — Wez Furlong — 2006-03-27T12:38:11+00:00

URL: https://externals.io/message/22592#22593 · In reply to: #22592

That patch won't work if you build the posix extension shared and don't load it.

In addition, it's most likely too late to capture the real errno value
that you're looking for; PHP does a decent amount of stuff between the
time that the low level syscall fails and the point that you sample
it.

On top of that, the failure code may not even be representable as an
errno--for example, when getaddrinfo() fails the reason is returned in
a different "number space" outside of the usual errno "protocol". 
Webdav streams may fail to open due to 404 errors at a level that
doesn't even cause errno to be set, similarly for user-space or other
extension streams.

--Wez.


> Hi all
>
> Attached is a patch (against HEAD) to allow codes like:
> $fp = @fopen("/unwritabledirectory/filename", "w");
> if (!$fp) {
> printf("The errornr was: %d", `posix_get_last_error()`);
> }
>
> Fixes bug #36868
>
> (If, for what ever reason, the patch doesn't come through:
> http://php.is/bugs/36868/posix.patch.txt )
> - Hannes
