php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36868 fopen does not set errno for posix_get_last_error
Submitted: 2006-03-27 06:25 UTC Modified: 2017-01-20 20:50 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: dgatwood at mac dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.1.2 OS: Mac OS X
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dgatwood at mac dot com
New email:
PHP Version: OS:

 

 [2006-03-27 06:25 UTC] dgatwood at mac dot com
Description:
------------
On Mac OS X, when fopen() fails with a permission denied 
error, the result of a subsequent posix_get_last_error() 
call is zero (0).  I would expect this to be set to the 
value of errno returned by the underlying open or fopen 
call.

I would also expect this to work for put_file_contents, but 
also get a rather useless zero when calling 
posix_get_last_error() after that fails.  However, since 
that isn't a POSIX function, I can accept that it wouldn't 
behave in this way... but fopen is a standard POSIX 
function, and should be setting errno.

Currently, it appears that without explicitly doing a stat 
on the directory, it is impossible to distinguish a 
permissions problem from some other error return (e.g. file 
exists, I/O error, etc.).


Reproduce code:
---------------
$fp = fopen("/unwritabledirectory/filename", "w");
if (!$fp) {
print "Error was: ".posix_get_last_error().".\n";
}


Expected result:
----------------
I would expect the fopen to fail with a permission denied 
error, errno to be set appropriately, and posix_get_last_error
() to fetch that value.


Actual result:
--------------
Error is always zero (0).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-20 20:50 UTC] heiglandreas@php.net
-Status: Open +Status: Not a bug -Package: Feature/Change Request +Package: *General Issues
 [2017-01-20 20:50 UTC] heiglandreas@php.net
posix_get_last_error — Retrieve the error number set by the last posix function that failed - fopen is not part of the posix-extension. So this is not a bug.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 20:00:02 2026 UTC