From a54fe77c04c7c2bda913ff63b0463417fb28794c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 14 Jan 2016 19:40:19 +0100 Subject: misread specification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- include/ctype.h | 20 ++++++++------------ src/ctype.c | 10 ---------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/include/ctype.h b/include/ctype.h index 6da0ae2..8f253c1 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -256,11 +256,6 @@ int (isxdigit)(int) /* [0x30, 0x39], [0x41, 0x46], [0x61, 0x66] */ * Convert a uppercase ASCII character to * an lowercase ASCII character. * - * The function's behaviour is unspecified - * of the character is not alphabetical. - * You should consider running - * `(isupper(c) ? tolower(c) : c)` instead. - * * @etymology Convert character (to) (lower)case! * * @param c The character. @@ -272,17 +267,15 @@ int (isxdigit)(int) /* [0x30, 0x39], [0x41, 0x46], [0x61, 0x66] */ */ int (tolower)(int) /* [0x41, 0x5A] -> [0x61, 0x7A] */ __GCC_ONLY(__attribute__((__const__, __warn_unused_result__))); -#define tolower(c) (int)((unsigned)(c) | 0x20) +#if defined (__GNUC__) +# define tolower(c) \ + ({ int __c = (int)(unsigned)(c); (islower(__c) ? (__c | 0x20) : __c; }) +#endif /** * Convert a lowercase ASCII character to * an uppercase ASCII character. * - * The function's behaviour is unspecified - * of the character is not alphabetical. - * You should consider running - * `(isupper(c) ? tolower(c) : c)` instead. - * * @etymology Convert character (to) (upper)case! * * @param c The character. @@ -294,7 +287,10 @@ int (tolower)(int) /* [0x41, 0x5A] -> [0x61, 0x7A] */ */ int (toupper)(int) /* [0x61, 0x7A] -> [0x41, 0x5A] */ __GCC_ONLY(__attribute__((__const__, __warn_unused_result__))); -#define toupper(c) (int)((unsigned)(c) & (unsigned)~0x20) +#if defined (__GNUC__) +# define toupper(c) \ + ({ int __c = (int)(unsigned)(c); (isupper(__c) ? (__c & ~0x20) : __c; }) +#endif diff --git a/src/ctype.c b/src/ctype.c index 0909905..a65741a 100644 --- a/src/ctype.c +++ b/src/ctype.c @@ -231,11 +231,6 @@ int (isxdigit)(int c) * Convert a uppercase ASCII character to * an lowercase ASCII character. * - * The function's behaviour is unspecified - * of the character is not alphabetical. - * You should consider running - * `(isupper(c) ? tolower(c) : c)` instead. - * * @etymology Convert character (to) (lower)case! * * @param c The character. @@ -255,11 +250,6 @@ int (tolower)(int c) * Convert a lowercase ASCII character to * an uppercase ASCII character. * - * The function's behaviour is unspecified - * of the character is not alphabetical. - * You should consider running - * `(isupper(c) ? tolower(c) : c)` instead. - * * @etymology Convert character (to) (upper)case! * * @param c The character. -- cgit v1.2.3-70-g09d2