Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/ctype/tolower.c')
-rw-r--r--newlib/libc/ctype/tolower.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/newlib/libc/ctype/tolower.c b/newlib/libc/ctype/tolower.c
index bdd22bfc5..66ba7233c 100644
--- a/newlib/libc/ctype/tolower.c
+++ b/newlib/libc/ctype/tolower.c
@@ -46,10 +46,31 @@ No supporting OS subroutines are required.
#include <_ansi.h>
#include <ctype.h>
+#if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS)
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <wctype.h>
+#include <wchar.h>
+#endif
#undef tolower
int
_DEFUN(tolower,(c),int c)
{
- return isupper(c) ? (c) - 'A' + 'a' : c;
+#if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS)
+ if ((unsigned char) c <= 0x7f)
+ return isupper (c) ? c - 'A' + 'a' : c;
+ else if (c != EOF && MB_CUR_MAX == 1 && isupper (c))
+ {
+ char s[MB_LEN_MAX] = { c, '\0' };
+ wchar_t wc;
+ if (mbtowc (&wc, s, 1) >= 0
+ && wctomb (s, (wchar_t) towlower ((wint_t) wc)) == 1)
+ c = s[0];
+ }
+ return c;
+#else
+ return isupper(c) ? (c) - 'A' + 'a' : c;
+#endif
}