Created attachment 197167 [details] patch to make time.h C11 and POSIX 1003.1b-1993 compliant The problems: - struct timespec is only visible if _POSIX_C_SOURCE >= 199309 even though it is in the C11 standard (ISO/IEC 9899:201x 7.27.1) - timespec_get is not behind any feature test macros, but it is only defined in C11 (ISO/IEC 9899:201x 7.27.2.5) Related headers: - time.h: includes timespec.h if _POSIX_C_SOURCE >= 19930, defines timespec_get and TIME_UTC unconditionally - timespec.h: defines some BSD-specific macros, itimerspec, and includes _timespec.h - _timespec.h: defines struct timespec A summary of which symbols are defined in which standard: - itimerspec: POSIX 1003.1b-1993 - timespec: POSIX 1003.1b-1993, C11 - timespec_get: C11 - TIME_UTC: C11 The patch: I did not really know what would be the proper approach to fix this, so I went with a solution that does not require touching _timespec.h and timespec.h. The attached patch puts timespec_get and TIME_UTC behind __STDC_VERSION__ >= 201112L guard. It also includes _timespec.h inside that guard, so we get struct timespec.
The .c part of the patch is certainly bogus. For the header, see https://reviews.freebsd.org/D17174 . I think that your suggestion to make timespec visible to C11 consumers is correct, but still this is not a final patch.
(In reply to Konstantin Belousov from comment #1) Ah, sorry, I've tried searching for this, but somehow missed the Phabricator issue. Thanks for the link!
I've updated D17174 to use __ISO_C_VISIBLE, include sys/_timespec.h, and use __BSD_VISABLE. I agree with kib that the change to libc is wrong and we should always provide the symbol.
I'll handle this since I've got a review open.
A commit references this bug: Author: brooks Date: Tue Sep 18 15:31:24 UTC 2018 New revision: 338751 URL: https://svnweb.freebsd.org/changeset/base/338751 Log: Fix C11 and POSIX 1003.1b-1993 compliance in time.h Only expose timespec_get in C11, C++17, or BSD code. Always define struct timespect if defining timespec_get. PR: 231425 Reviewed by: kib Approved by: re (gjb) Differential Revision: https://reviews.freebsd.org/D17174 Changes: head/include/time.h