source: trunk/libs/newlib/src/newlib/libc/ctype/tolower_l.c @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 978 bytes
Line 
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
11
12int
13tolower_l (int c, struct __locale_t *locale)
14{
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))
20    {
21      char s[MB_LEN_MAX] = { c, '\0' };
22      wchar_t wc;
23      mbstate_t state;
24
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];
31    }
32  return c;
33#else
34  return isupper_l (c, locale) ? (c) - 'A' + 'a' : c;
35#endif
36}
Note: See TracBrowser for help on using the repository browser.