From 0967fc9724201c70476ea058c9f648ae75d0c9ed Mon Sep 17 00:00:00 2001 From: jca Date: Sun, 4 Feb 2024 13:03:18 +0000 Subject: [PATCH] Move ctype.h defines to the _CTYPE_ prefix, avoids clashes with identifiers in ports Even if those _[BCNLPSUX] defines are in the reserved namespace, some ports make use of those identifiers and thus need pointless headscratching and patches. Just use a longer reserved prefix. We can't just #undef those defines as they are used in libc. Change similar to what NetBSD did around 2010. Went through base builds and an amd64 bulk build, the only fallout was lib(e)stdc++ base_ctype.h. "make includes" will install the latest ctype.h and libstdc++ ctype_base.h. "makes sense" deraadt@, ok sthen@ tb@ --- include/ctype.h | 45 +++++++++++++++++++++++------------------- lib/libc/gen/ctype_.c | 12 ++++++++++- lib/libc/gen/isctype.c | 29 ++++++++++++++++----------- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/include/ctype.h b/include/ctype.h index e90d375c8d2..6dd2ced25ea 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ctype.h,v 1.25 2017/09/05 03:16:13 schwarze Exp $ */ +/* $OpenBSD: ctype.h,v 1.26 2024/02/04 13:03:18 jca Exp $ */ /* $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $ */ /* @@ -42,14 +42,14 @@ #include -#define _U 0x01 -#define _L 0x02 -#define _N 0x04 -#define _S 0x08 -#define _P 0x10 -#define _C 0x20 -#define _X 0x40 -#define _B 0x80 +#define _CTYPE_U 0x01 +#define _CTYPE_L 0x02 +#define _CTYPE_N 0x04 +#define _CTYPE_S 0x08 +#define _CTYPE_P 0x10 +#define _CTYPE_C 0x20 +#define _CTYPE_X 0x40 +#define _CTYPE_B 0x80 #if __POSIX_VISIBLE >= 200809 #ifndef _LOCALE_T_DEFINED_ @@ -114,57 +114,62 @@ int toupper_l(int, locale_t); __only_inline int isalnum(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_U|_L|_N))); + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & + (_CTYPE_U|_CTYPE_L|_CTYPE_N))); } __only_inline int isalpha(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_U|_L))); + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & + (_CTYPE_U|_CTYPE_L))); } __only_inline int iscntrl(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _C)); + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_C)); } __only_inline int isdigit(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _N)); + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_N)); } __only_inline int isgraph(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_P|_U|_L|_N))); + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & + (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N))); } __only_inline int islower(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _L)); + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_L)); } __only_inline int isprint(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_P|_U|_L|_N|_B))); + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & + (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N|_CTYPE_B))); } __only_inline int ispunct(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _P)); + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_P)); } __only_inline int isspace(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _S)); + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_S)); } __only_inline int isupper(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _U)); + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_U)); } __only_inline int isxdigit(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_N|_X))); + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & + (_CTYPE_N|_CTYPE_X))); } __only_inline int tolower(int _c) diff --git a/lib/libc/gen/ctype_.c b/lib/libc/gen/ctype_.c index 89722443351..9742c9f160e 100644 --- a/lib/libc/gen/ctype_.c +++ b/lib/libc/gen/ctype_.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ctype_.c,v 1.12 2015/09/19 04:02:21 guenther Exp $ */ +/* $OpenBSD: ctype_.c,v 1.13 2024/02/04 13:03:18 jca Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. * All rights reserved. @@ -36,6 +36,16 @@ #include #include "ctype_private.h" +/* Shorter names for the defines provided by */ +#define _U _CTYPE_U +#define _L _CTYPE_L +#define _N _CTYPE_N +#define _S _CTYPE_S +#define _P _CTYPE_P +#define _C _CTYPE_C +#define _X _CTYPE_X +#define _B _CTYPE_B + const char _C_ctype_[1 + CTYPE_NUM_CHARS] = { 0, _C, _C, _C, _C, _C, _C, _C, _C, diff --git a/lib/libc/gen/isctype.c b/lib/libc/gen/isctype.c index a4e944ca7df..2891ccd45e8 100644 --- a/lib/libc/gen/isctype.c +++ b/lib/libc/gen/isctype.c @@ -1,4 +1,4 @@ -/* $OpenBSD: isctype.c,v 1.12 2015/09/13 11:38:08 guenther Exp $ */ +/* $OpenBSD: isctype.c,v 1.13 2024/02/04 13:03:18 jca Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. * All rights reserved. @@ -41,7 +41,8 @@ int isalnum(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N))); + return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & + (_CTYPE_U|_CTYPE_L|_CTYPE_N))); } DEF_STRONG(isalnum); @@ -49,7 +50,8 @@ DEF_STRONG(isalnum); int isalpha(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L))); + return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & + (_CTYPE_U|_CTYPE_L))); } DEF_STRONG(isalpha); @@ -65,7 +67,7 @@ DEF_STRONG(isblank); int iscntrl(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _C)); + return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_C)); } DEF_STRONG(iscntrl); @@ -73,7 +75,7 @@ DEF_STRONG(iscntrl); int isdigit(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N)); + return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_N)); } DEF_STRONG(isdigit); @@ -81,7 +83,8 @@ DEF_STRONG(isdigit); int isgraph(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N))); + return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & + (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N))); } DEF_STRONG(isgraph); @@ -89,7 +92,7 @@ DEF_STRONG(isgraph); int islower(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _L)); + return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_L)); } DEF_STRONG(islower); @@ -97,7 +100,8 @@ DEF_STRONG(islower); int isprint(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B))); + return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & + (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N|_CTYPE_B))); } DEF_STRONG(isprint); @@ -105,7 +109,7 @@ DEF_STRONG(isprint); int ispunct(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _P)); + return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_P)); } DEF_STRONG(ispunct); @@ -113,7 +117,7 @@ DEF_STRONG(ispunct); int isspace(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S)); + return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_S)); } DEF_STRONG(isspace); @@ -121,7 +125,7 @@ DEF_STRONG(isspace); int isupper(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _U)); + return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_U)); } DEF_STRONG(isupper); @@ -129,7 +133,8 @@ DEF_STRONG(isupper); int isxdigit(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_N|_X))); + return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & + (_CTYPE_N|_CTYPE_X))); } DEF_STRONG(isxdigit); -- 2.20.1