Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ctype.h: remove duplicate isdigit() helper

gcc warns a few thousand times about the isdigit() shadow:

include/linux/ctype.h:26:19: warning: declaration of 'isdigit' shadows a built-in function [-Wshadow]

As there is already a compiler builtin, just use that, and make
it clear we do that by defining a macro. Unfortunately, clang
does not have the isdigit() builtin, so this has to be conditional.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+22 -4
+11
include/linux/compiler_types.h
··· 64 64 /* Attributes */ 65 65 #include <linux/compiler_attributes.h> 66 66 67 + /* Builtins */ 68 + 69 + /* 70 + * __has_builtin is supported on gcc >= 10, clang >= 3 and icc >= 21. 71 + * In the meantime, to support gcc < 10, we implement __has_builtin 72 + * by hand. 73 + */ 74 + #ifndef __has_builtin 75 + #define __has_builtin(x) (0) 76 + #endif 77 + 67 78 /* Compiler specific macros. */ 68 79 #ifdef __clang__ 69 80 #include <linux/compiler-clang.h>
+11 -4
include/linux/ctype.h
··· 2 2 #ifndef _LINUX_CTYPE_H 3 3 #define _LINUX_CTYPE_H 4 4 5 + #include <linux/compiler.h> 6 + 5 7 /* 6 8 * NOTE! This ctype does not handle EOF like the standard C 7 9 * library is required to. ··· 25 23 #define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0) 26 24 #define isalpha(c) ((__ismask(c)&(_U|_L)) != 0) 27 25 #define iscntrl(c) ((__ismask(c)&(_C)) != 0) 28 - static inline int isdigit(int c) 29 - { 30 - return '0' <= c && c <= '9'; 31 - } 32 26 #define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0) 33 27 #define islower(c) ((__ismask(c)&(_L)) != 0) 34 28 #define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0) ··· 36 38 37 39 #define isascii(c) (((unsigned char)(c))<=0x7f) 38 40 #define toascii(c) (((unsigned char)(c))&0x7f) 41 + 42 + #if __has_builtin(__builtin_isdigit) 43 + #define isdigit(c) __builtin_isdigit(c) 44 + #else 45 + static inline int isdigit(int c) 46 + { 47 + return '0' <= c && c <= '9'; 48 + } 49 + #endif 39 50 40 51 static inline unsigned char __tolower(unsigned char c) 41 52 {