source: trunk/libs/newlib/src/newlib/libc/ctype/tolower.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: 2.2 KB
Line 
1/*
2FUNCTION
3        <<tolower>>, <<tolower_l>>---translate characters to lowercase
4
5INDEX
6        tolower
7
8INDEX
9        tolower_l
10
11INDEX
12        _tolower
13
14SYNOPSIS
15        #include <ctype.h>
16        int tolower(int <[c]>);
17        int _tolower(int <[c]>);
18
19        #include <ctype.h>
20        int tolower_l(int <[c]>, locale_t <[locale]>);
21
22
23DESCRIPTION
24<<tolower>> is a macro which converts uppercase characters to lowercase,
25leaving all other characters unchanged.  It is only defined when
26<[c]> is an integer in the range <<EOF>> to <<255>>.
27
28<<tolower_l>> is like <<tolower>> but performs the function based on the
29locale specified by the locale object locale.  If <[locale]> is
30LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined.
31
32You can use a compiled subroutine instead of the macro definition by
33undefining this macro using `<<#undef tolower>>' or `<<#undef tolower_l>>'.
34
35<<_tolower>> performs the same conversion as <<tolower>>, but should
36only be used when <[c]> is known to be an uppercase character (<<A>>--<<Z>>).
37
38RETURNS
39<<tolower>>, <<tolower_l>> return the lowercase equivalent of <[c]> when
40<[c]> is an uppercase character, and <[c]> otherwise.
41
42<<_tolower>> returns the lowercase equivalent of <[c]> when it is a
43character between <<A>> and <<Z>>.  If <[c]> is not one of these
44characters, the behaviour of <<_tolower>> is undefined.
45
46PORTABILITY
47<<tolower>> is ANSI C.  <<_tolower>> is not recommended for portable programs.
48<<tolower_l>> is POSIX-1.2008.
49
50No supporting OS subroutines are required.
51*/ 
52
53#include <_ansi.h>
54#include <ctype.h>
55#if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS)
56#include <limits.h>
57#include <stdio.h>
58#include <stdlib.h>
59#include <wctype.h>
60#include <wchar.h>
61#endif
62
63#undef tolower
64int
65tolower (int c)
66{
67#if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS)
68  if ((unsigned char) c <= 0x7f) 
69    return isupper (c) ? c - 'A' + 'a' : c;
70  else if (c != EOF && MB_CUR_MAX == 1 && isupper (c))
71    {
72      char s[MB_LEN_MAX] = { c, '\0' };
73      wchar_t wc;
74      if (mbtowc (&wc, s, 1) >= 0
75          && wctomb (s, (wchar_t) towlower ((wint_t) wc)) == 1)
76        c = (unsigned char) s[0];
77    }
78  return c;
79#else
80  return isupper(c) ? (c) - 'A' + 'a' : c;
81#endif
82}
Note: See TracBrowser for help on using the repository browser.