From 56593bc6ca97780c9458607196e5c3a630367094 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 17 Jul 2023 14:45:26 -0700 Subject: [PATCH] scripts/checkpatch: Check for patches adding #defines for libc APIs All code in the Zephyr core must use only the Zephyr C library API according to rules A.4 and A.5. Such code is not permitted to request API extensions from the C library via any of the API request mechanisms. This addition to checkpatch.pl verifies that patches don't #define any of these: __STRICT_ANSI__ _POSIX_SOURCE _POSIX_C_SOURCE _XOPEN_SOURCE _ISOC99_SOURCE _ISOC11_SOURCE _ATFILE_SOURCE _GNU_SOURCE _BSD_SOURCE _SVID_SOURCE _DEFAULT_SOURCE Reference: #49922 Signed-off-by: Keith Packard --- scripts/checkpatch.pl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 6e55520a2afe65..57ca4a17749bab 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -592,6 +592,20 @@ sub hash_show_words { ["__ATTR", 2], ); +our $api_defines = qr{(?x: + _ATFILE_SOURCE| + _BSD_SOURCE| + _DEFAULT_SOURCE + _GNU_SOURCE| + _ISOC11_SOURCE| + _ISOC99_SOURCE| + _POSIX_C_SOURCE| + _POSIX_SOURCE| + _SVID_SOURCE| + _XOPEN_SOURCE| + _XOPEN_SOURCE_EXTENDED| +)}; + my $word_pattern = '\b[A-Z]?[a-z]{2,}\b'; #Create a search pattern for all these functions to speed up a loop below @@ -6527,6 +6541,13 @@ sub process { } } +# check for feature test macros that request C library API extensions, violating rules A.4 and A.5 + + if ($line =~ /#\s*define\s+$api_defines/) { + ERROR("API_DEFINE", + "do not specify a non-Zephyr API for libc\n" . "$here$rawline\n"); + } + # check for IS_ENABLED() without CONFIG_ ($rawline for comments too) if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^CONFIG_/) { WARN("IS_ENABLED_CONFIG",