This line: > $ cat x.c > #include <sys/file.h> fails when compiled with -D_POSIX_C_SOURCE=200809L: > $ cc -c x.c -D_POSIX_C_SOURCE=200809L > In file included from x.c:2: > /usr/include/sys/file.h:233:2: error: unknown type name 'u_int' > u_int xf_flag; /* flags (see fcntl.h) */ > ^ > 1 error generated. The vtk-9,1,0 fails for this reason. I am not sure but shouldn't base headers compile with any choices of C standard level?
Since sys/file.h is not defined by POSIX-1.2008, including it at all is undefined behavior. Why does vtk need it? I'm unfamiliar with that program.
(In reply to Warner Losh from comment #1) Also, the name u_int is only defined in sys/types.h, so this likely is unrelated to the POSIX_C_SOURCE stuff and instead based on the expectation that sys/files.h is independently includable. But, u_int isn't visible when POSIX_C_SOURCE is defined (since it's hidden behind __BSD_VISIBLE. It also uses kvaddr_t, ksize_t and maybe a few others that should likely also be protected with __BSD_VISIBLE since POSIX_C_SOURCE says define what's in posix and nothing else. I'd wager the name-space-clean fix is to make xfile only __BSD_VISIBLE, but that too would likely break vtk since it's already doing dubious things with it and including files that aren't defined in the posix standard. Most likely, though, it wants to use flock (also not defined in POSIX.1-2008), which is the only function I could find in base man pages that mention sys/file.h inclusion. However, if it wants this extension, shouldn't it not be defining that it doesn't want extensions?
The upstream bug report: https://gitlab.kitware.com/vtk/vtk/-/issues/18391
VTK is a very large library for scientific and industrial visualization.
(In reply to Yuri Victorovich from comment #4) set (HDF_EXTRA_C_FLAGS -D_POSIX_C_SOURCE=200809L) needs to be removed from ThirdParty/hdf5/vtkhdf5/config/cmake_ext_mod/ConfigureChecks.cmake in the FreeBSD port. It uses flock, which isn't in POSIX, so setting POSIX_C_SOURCE is likely inappropriate. It's also a bug that we try to define xfile when __BSD_VISIBLE is defined, but fixing that wouldn't fix hdf5 inside of vtk.
The other workaround for this would be to add -D__BSD_VISIBLE=1 to the compliation. The hdf sources already do something similar for _GNU_SOURCE to bring in extra functionality that's only in Linux, but we have no similar _BSD_SOURCE or _FREEBSD_SOURCE (NetBSD and OpenBSD both have _NETBSD_SORUCE or _OPENBSD_SOURCE respectively). My inclination is to define _FREEBSD_SOURCE and have hdf use it (and maybe __BSD_VISIBLE=1 as a transitionary workaround), but I'm open for the least painful way to be both compliant with POSIX_C_SOURCE and the desire for enabling extensions.
(In reply to Warner Losh from comment #6) Thanks Warner, I'll use this workaround. Yuri
(In reply to Warner Losh from comment #6) FYI: Adding -D__BSD_VISIBLE=1 causes another failure: > /usr/include/time.h:175:23: error: unknown type name 'timer_t'; did you mean 'time_t'? > int timer_oshandle_np(timer_t timerid); > ^ > /usr/include/time.h:68:18: note: 'time_t' declared here > typedef __time_t time_t; > ^ But adding -Du_int=unsigned works. So I would use this workaround for the time being until it is resolved outside of the port.
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(+)
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(+)
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(+)