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

Michael Kerrisk (man-pages) mtk.manpages@gmail.com
Sun May 9 20:02:12 GMT 2021


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 );
> 


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/


More information about the Libc-alpha mailing list