lib/std: Make usage of PermissionDenied & AccessDenied consistent #23007
+113
−98
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR (mostly) consistently maps
.ACCES
intoerrors.AccessDenied
and.PERM
intoerrors.PermissionDenied
. These two similar error codes are a POSIX thing whereEACCES
is returned if the file mode bits (user/group/other rwx bits) disallow access. WhereasEPERM
is returned if something else denies access (e.g., immutable bit, SELinux, capabilities, etc). Most of the change is straight-forward and starts in the lib/std/posix.zig code, and propagates up to the std.os.* and std.fs.* layers that pass the Posix errors on. There are a couple pre-existing exceptions to this general rule where more "useful" errors are returned (e.g.,errors.Locked
forEACCES
infcntl
).POSIX makes this extra confusing because the
EACCES
errno stringifies as "Permission Denied" (EPERM
stringifies as "Operation Not Permitted"). I think it is clearer to map the Zig made up names to the errno token, thusAccessDenied
forEACCES
andPermissionDenied
forEPERM
, but I could be persuaded to use a different mapping. OTOH, I think it would be even less confusing if Zig didn't try to "fix" the errno names and just returnederrors.EACCES
anderrors.EPERM
, but that is not this PR.I changed some Windows code (both in posix.zig and not) to consistently map the Windows
ACCESS_DENIED
error code toerrors.AccessDenied
. My general rule here is that the Zig error codes should reflect the platform's error as directly as possible unless there is a good reason.Fixes #16782