From cad7949c6e0882e8ad9db6b7384714ca0ed3f6ea Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Fri, 14 Aug 2026 23:11:10 -0400 Subject: [PATCH] COMP: Build as ISO C11 with no compiler extensions The build never set a C standard, so it used the compiler default. Set CMAKE_C_STANDARD 11 with C_EXTENSIONS OFF. Two POSIX dependencies were being satisfied silently by the gnu default and now have to be requested: cifti/afni_xml.c strdup(), 3 uses. Without a declaration this was an implicit function declaration returning int assigned to char * -- an error in C99 onward. nifti1_io.c, popen()/pclose() in the optional PIGZ write path, nifti2_io.c only compiled with -DFSLSTYLE_PIGZ_SUPPORT=ON. Each file defines _POSIX_C_SOURCE 200809L ahead of its includes, so the dependency is visible where it is taken. (cherry picked from commit 49b48b49d9e91c955a2fa36958a8e454c5c5c864) --- CMakeLists.txt | 6 ++++++ cifti/afni_xml.c | 4 ++++ nifti2/nifti2_io.c | 3 +++ niftilib/nifti1_io.c | 3 +++ 4 files changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd551f15..92b9631b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,12 @@ project(NIFTI DESCRIPTION "Niftilib is a set of i/o libraries for reading and writing files in the nifti-1 data format. nifti-1 is a binary file format for storing medical image data, e.g. magnetic resonance image (MRI) and functional MRI (fMRI) brain images." LANGUAGES C) +# Sources needing POSIX interfaces (strdup, popen) request them with +# _POSIX_C_SOURCE at the top of the file. +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) include(nifti_macros) diff --git a/cifti/afni_xml.c b/cifti/afni_xml.c index a9910a1b..781d0892 100644 --- a/cifti/afni_xml.c +++ b/cifti/afni_xml.c @@ -1,3 +1,7 @@ +/* strdup() is POSIX, not ISO C11; must precede every #include. + C23 adds it, so this define goes away once C23 is the floor. */ +#define _POSIX_C_SOURCE 200809L + #include #include #include diff --git a/nifti2/nifti2_io.c b/nifti2/nifti2_io.c index c8cc6b23..6bd74a8d 100644 --- a/nifti2/nifti2_io.c +++ b/nifti2/nifti2_io.c @@ -1,3 +1,6 @@ +/* popen()/pclose() in the PIGZ write path are POSIX, not ISO C11. */ +#define _POSIX_C_SOURCE 200809L + #define NIFTI2_IO_C #include diff --git a/niftilib/nifti1_io.c b/niftilib/nifti1_io.c index eb8887f3..502b76ab 100644 --- a/niftilib/nifti1_io.c +++ b/niftilib/nifti1_io.c @@ -1,3 +1,6 @@ +/* popen()/pclose() in the PIGZ write path are POSIX, not ISO C11. */ +#define _POSIX_C_SOURCE 200809L + #define NIFTI1_IO_C #include