Re: mkstemp(3)
Garrett Wollman <[email protected]>
| Newsgroups | org.kernel.vger.linux-man |
|---|---|
| Message-ID | <[email protected]> |
<<On Thu, 7 May 2026 21:34:03 -0400, Douglas McIlroy <[email protected]> said: > Posix System Interfaces Section 2.2 tells me that I should #define > _POSIX_C_SOURCE before #include <stdlib.h>. That fact is missing from > Linux's man 3 mkstemp. Arguably the Posix description of mkstemp > should mention it, too. <div class="standards-lawyering"> Conveniently, POSIX.1-2008 removed mkstemp from the XSI option and made it standard (shaded only CX and not XSI) so in 2008 and newer, you don't have to define _XOPEN_SOURCE. You do have to set the correct _POSIX_C_SOURCE value for the standard your implementation confirms to, which currently means that you can only use C17 in POSIX.1-2024 and cannot use C23 at all. This may be the source of the confusion: for ISO C, "the implementation" is the compiler, header files, and standard library, so your C23 compiler ships with versions of those that meet the requirements of the C23 standard. For POSIX on the other hand, "the implementation" is the entire operating system, which must support one and only one specific version of ISO C. It is up to your operating system supplier (e.g. Linux distro packager) to build a <stdlib.h> that meets the requirements of POSIX if they want to claim to be POSIX-compliant. (Very likely they don't actually care about formal compliance.) An application that uses C23 features (or indeed that is compiled with anything other than the POSIX.1-2024 `c17` utility) is not a conforming POSIX application and its behavior is undefined. (Likewise POSIX.1-2008 requires compilation with the `c99` utility, since that standard is aligned to C99.) </div> -GAWollman