[3/3] open.2: Remove unused <sys/stat.h>

Message ID 20210421224418.143065-3-alx.manpages@gmail.com
State Not applicable
Headers
Series [1/3] alloc_hugepages.2, arch_prctl.2, capget.2, clone.2, delete_module.2, execveat.2, exit_group.2, get_robust_list.2, getunwind.2, init_module.2: Add note about the use of syscall(2) |

Commit Message

Alejandro Colomar April 21, 2021, 10:44 p.m. UTC
  I can't see a reason to include it.  <fcntl.h> provides O_*
constants for 'flags', S_* constants for 'mode', and mode_t.

Probably a long time ago, some of those weren't defined in
<fcntl.h>, and both headers needed to be included, or maybe it's
a historical error.

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
---
 man2/open.2 | 1 -
 1 file changed, 1 deletion(-)
  

Comments

Michael Kerrisk \(man-pages\) May 9, 2021, 8:02 p.m. UTC | #1
Hello Alex,

On 4/22/21 10:44 AM, Alejandro Colomar wrote:
> I can't see a reason to include it.  <fcntl.h> provides O_*
> constants for 'flags', S_* constants for 'mode', and mode_t.
> 
> Probably a long time ago, some of those weren't defined in
> <fcntl.h>, and both headers needed to be included, or maybe it's
> a historical error.
> 
> Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>

So, I am uncertain what to do about this patch. I agree
that we don't need the <sys/stat.h> on Linux.

But, look at open(3p):

    SYNOPSIS
       #include <sys/stat.h>
       #include <fcntl.h>

       int open(const char *path, int oflag, ...);

       O_CREAT       [...] and the access permission bits  (see
                     <sys/stat.h>)  of  the file mode shall be set to the
                     value of the argument following the  oflag  argument
                     taken  as type mode_t modified as follows...

But, seemingly in contradiction, fcntl.h(0p) says:

       The <fcntl.h> header shall define the symbolic constants for  file
       modes for use as values of mode_t as described in <sys/stat.h>.

It almost seems like a small bug in POSIX.

I see also that open(2) on FreeBSD mentions only the need to 
include <fcntl.h>.

What are your thoughts on the above. I'm willing to apply your 
patch if you still think we should apply it.

Thanks,

Michael

> ---
>  man2/open.2 | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/man2/open.2 b/man2/open.2
> index bac1ee806..1bcd995f4 100644
> --- a/man2/open.2
> +++ b/man2/open.2
> @@ -53,7 +53,6 @@
>  open, openat, creat \- open and possibly create a file
>  .SH SYNOPSIS
>  .nf
> -.B #include <sys/stat.h>
>  .B #include <fcntl.h>
>  .PP
>  .BI "int open(const char *" pathname ", int " flags );
>
  
Alejandro Colomar May 9, 2021, 8:09 p.m. UTC | #2
Hi Michael!

On 5/9/21 10:02 PM, Michael Kerrisk (man-pages) wrote:
> It almost seems like a small bug in POSIX.

Yes, it seems so.

> 
> I see also that open(2) on FreeBSD mentions only the need to 
> include <fcntl.h>.
> 
> What are your thoughts on the above. I'm willing to apply your 
> patch if you still think we should apply it.

We could file a bug to the Open Group.  Could you do that?  I don't know
how to do it.  Let's wait and see.

I don't have any patches that depend on this one, so we can hold on.
I'll ping you in a month or so if needed.  I guess that POSIX will
confirm that we can remove it, but let's wait.

Thanks,

Alex
  

Patch

diff --git a/man2/open.2 b/man2/open.2
index bac1ee806..1bcd995f4 100644
--- a/man2/open.2
+++ b/man2/open.2
@@ -53,7 +53,6 @@ 
 open, openat, creat \- open and possibly create a file
 .SH SYNOPSIS
 .nf
-.B #include <sys/stat.h>
 .B #include <fcntl.h>
 .PP
 .BI "int open(const char *" pathname ", int " flags );