aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2016-01-14 19:40:19 +0100
committerMattias Andrée <maandree@member.fsf.org>2016-01-14 19:41:01 +0100
commita54fe77c04c7c2bda913ff63b0463417fb28794c (patch)
tree1ef85655a56b967a594d54813636b7196aa6ceab
parentpartially split malloc.c (diff)
downloadslibc-a54fe77c04c7c2bda913ff63b0463417fb28794c.tar.gz
slibc-a54fe77c04c7c2bda913ff63b0463417fb28794c.tar.bz2
slibc-a54fe77c04c7c2bda913ff63b0463417fb28794c.tar.xz
misread specification
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to '')
-rw-r--r--include/ctype.h20
-rw-r--r--src/ctype.c10
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.