Skip to content

Commit caabdd0

Browse files
committed
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>
1 parent f44ca08 commit caabdd0

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎include/linux/compiler_types.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { }
6464
/* Attributes */
6565
#include <linux/compiler_attributes.h>
6666

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+
6778
/* Compiler specific macros. */
6879
#ifdef __clang__
6980
#include <linux/compiler-clang.h>

‎include/linux/ctype.h‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#ifndef _LINUX_CTYPE_H
33
#define _LINUX_CTYPE_H
44

5+
#include <linux/compiler.h>
6+
57
/*
68
* NOTE! This ctype does not handle EOF like the standard C
79
* library is required to.
@@ -23,10 +25,6 @@ extern const unsigned char _ctype[];
2325
#define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
2426
#define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
2527
#define iscntrl(c) ((__ismask(c)&(_C)) != 0)
26-
static inline int isdigit(int c)
27-
{
28-
return '0' <= c && c <= '9';
29-
}
3028
#define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
3129
#define islower(c) ((__ismask(c)&(_L)) != 0)
3230
#define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
@@ -39,6 +37,15 @@ static inline int isdigit(int c)
3937
#define isascii(c) (((unsigned char)(c))<=0x7f)
4038
#define toascii(c) (((unsigned char)(c))&0x7f)
4139

40+
#if __has_builtin(__builtin_isdigit)
41+
#define isdigit(c) __builtin_isdigit(c)
42+
#else
43+
static inline int isdigit(int c)
44+
{
45+
return '0' <= c && c <= '9';
46+
}
47+
#endif
48+
4249
static inline unsigned char __tolower(unsigned char c)
4350
{
4451
if (isupper(c))

0 commit comments

Comments
 (0)