Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / ctype / tolower_l.c
blob3b196c8d288f5e2d80c1f8792757969f29cd4f87
1 #include <_ansi.h>
2 #include <ctype.h>
3 #if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS)
4 #include <limits.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <wctype.h>
8 #include <wchar.h>
9 #include "../locale/setlocale.h"
10 #endif
12 int
13 tolower_l (int c, struct __locale_t *locale)
15 #if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS)
16 if ((unsigned char) c <= 0x7f)
17 return isupper_l (c, locale) ? c - 'A' + 'a' : c;
18 else if (c != EOF && __locale_mb_cur_max_l (locale) == 1
19 && isupper_l (c, locale))
21 char s[MB_LEN_MAX] = { c, '\0' };
22 wchar_t wc;
23 mbstate_t state;
25 memset (&state, 0, sizeof state);
26 if (locale->mbtowc (_REENT, &wc, s, 1, &state) >= 0
27 && locale->wctomb (_REENT, s,
28 (wchar_t) towlower_l ((wint_t) wc, locale),
29 &state) == 1)
30 c = (unsigned char) s[0];
32 return c;
33 #else
34 return isupper_l (c, locale) ? (c) - 'A' + 'a' : c;
35 #endif