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",