Skip to content
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

perlfunc/stat: fix description of S_ENFMT and S_IFMT #22203

Merged
merged 1 commit into from
May 17, 2024

Conversation

mauke
Copy link
Contributor

@mauke mauke commented May 9, 2024

S_ENFMT properly belongs to the group of permission bits (like setuid/setgid), not file types. On systems that have it (like AIX), it can be set/cleared with chmod(). (In fact, it usually shares its value with S_ISGID because enforced locking is signaled by the combination of a non-executable file with the setgid bit set.)

S_IFMT($mode) directly gives you one of the file types (S_IFREG, S_IFDIR, etc). You don't need to bit-and it further (especially not with the S_IS* functions), contrary to what the comment claims. (The confusion likely stems from the C side of things, where you'd do mode & S_IFMT to extract the file type from the mode bits, leading to code like (mode & S_IFMT) == S_IFDIR. But even then you could write S_ISDIR(mode) without any bit mask trickery.)

Most of the symbols in the "S_IF* constants" section don't start with "S_IF", so change to "S_I* constants" everywhere.

Most of the symbols in the "S_IF* functions" section don't start with "S_IF" (with the sole exception of S_IFMT, which is only a function in Perl; the C macro is a constant).
(Historical note: This section label used to make more sense because it documented S_IFMODE and S_IFMT functions, but the former was just a typo for S_IMODE.)

S_ENFMT properly belongs to the group of permission bits (like
setuid/setgid), not file types. On systems that have it (like AIX), it
can be set/cleared with chmod(). (In fact, it usually shares its value
with S_ISGID because enforced locking is signaled by the combination of
a non-executable file with the setgid bit set.)

S_IFMT($mode) directly gives you one of the file types (S_IFREG,
S_IFDIR, etc). You don't need to bit-and it further (especially not with
the S_IS* functions), contrary to what the comment claims. (The
confusion likely stems from the C side of things, where you'd do `mode &
S_IFMT` to extract the file type from the mode bits, leading to code
like `(mode & S_IFMT) == S_IFDIR`. But even then you could write
`S_ISDIR(mode)` without any bit mask trickery.)

Most of the symbols in the "S_IF* constants" section don't start with
"S_IF", so change to "S_I* constants" everywhere.

Most of the symbols in the "S_IF* functions" section don't start with
"S_IF" (with the sole exception of S_IFMT, which is only a function in
Perl; the C macro is a constant).
(Historical note: This section label used to make more sense because it
documented S_IFMODE and S_IFMT functions, but the former was just a typo
for S_IMODE.)
@richardleach
Copy link
Contributor

Makes sense & LGTM

Copy link
Contributor

@khwilliamson khwilliamson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough to attest to the accuracy, but lgtm

@mauke mauke merged commit 643108f into Perl:blead May 17, 2024
30 checks passed
@mauke mauke deleted the perlfunc-stat-constants-desc branch May 17, 2024 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants