Bug 234205 - /usr/include/sys/file.h uses the u_int typedef which causes C compilation to sometimes fail
Summary: /usr/include/sys/file.h uses the u_int typedef which causes C compilation to ...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 12.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-20 13:14 UTC by Andras Farkas
Modified: 2021-12-06 15:57 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andras Farkas 2018-12-20 13:14:42 UTC
If you compile a program, and give -D_XOPEN_SOURCE=700 to the compiler, and the program has #include <sys/file.h> the compiler gives an error like this:
/usr/include/sys/file.h:226:2: error: unknown type name 'u_int'
        u_int   xf_flag;        /* flags (see fcntl.h) */
and then bails out.
Why is the u_int typedef used instead of 'unsigned int' itself?  It's unnecessary other than to save a couple keystrokes while typing.
Comment 1 Jilles Tjoelker freebsd_committer 2018-12-27 18:52:37 UTC
The current implementation of the feature test macros like _XOPEN_SOURCE that request strict standards compliance is that the application is assumed not to need any extensions. For the most part, defining such a macro hides things not belonging to the selected standard from header files listed in the standard. If a header file is used that is not in the standard, this is a bad idea: it either fails (as you see here) or exposes extensions to the standard.
Comment 2 commit-hook freebsd_committer 2021-11-24 09:40:11 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=a2b53e53a3f38dd89b64500a2d2a1727baffe4f9

commit a2b53e53a3f38dd89b64500a2d2a1727baffe4f9
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2021-11-24 09:25:47 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2021-11-24 09:38:09 +0000

    sys/file.h: Allow inclusion when compiling for a strict namespace

    Although not part of the standard, this file is sometimes included with
    -D_POSIX_C_SOURCE=<value> or -D_XOPEN_SOURCE=<value>. Limit those
    sturctures that use types hidden by __BSD_VISIBLE to when they are
    visible.

    PR:                     259975, 234205
    Sponsored by:           Netflix

 sys/sys/file.h | 4 ++++
 1 file changed, 4 insertions(+)
Comment 3 Warner Losh freebsd_committer 2021-11-24 10:03:56 UTC
I'll note in passing that all the other files in sys/sys/*.h today that are self-contained will compile when specific feature macros are defined, except sys/file.h.
Comment 4 commit-hook freebsd_committer 2021-12-06 15:56:25 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5fb6ac34479dc0e23b5ff8f3ae74c6266cf32476

commit 5fb6ac34479dc0e23b5ff8f3ae74c6266cf32476
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2021-11-24 09:25:47 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2021-12-06 15:54:10 +0000

    sys/file.h: Allow inclusion when compiling for a strict namespace

    Although not part of the standard, this file is sometimes included with
    -D_POSIX_C_SOURCE=<value> or -D_XOPEN_SOURCE=<value>. Limit those
    sturctures that use types hidden by __BSD_VISIBLE to when they are
    visible.

    PR:                     259975, 234205
    Sponsored by:           Netflix

    (cherry picked from commit a2b53e53a3f38dd89b64500a2d2a1727baffe4f9)

 sys/sys/file.h | 4 ++++
 1 file changed, 4 insertions(+)
Comment 5 commit-hook freebsd_committer 2021-12-06 15:57:28 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=793fad727a33a5f539eb414e4f0b09aaee0a1b23

commit 793fad727a33a5f539eb414e4f0b09aaee0a1b23
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2021-11-24 09:25:47 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2021-12-06 15:55:58 +0000

    sys/file.h: Allow inclusion when compiling for a strict namespace

    Although not part of the standard, this file is sometimes included with
    -D_POSIX_C_SOURCE=<value> or -D_XOPEN_SOURCE=<value>. Limit those
    sturctures that use types hidden by __BSD_VISIBLE to when they are
    visible.

    PR:                     259975, 234205
    Sponsored by:           Netflix

    (cherry picked from commit a2b53e53a3f38dd89b64500a2d2a1727baffe4f9)

 sys/sys/file.h | 4 ++++
 1 file changed, 4 insertions(+)