1 | /* Copyright (c) 2002 Red Hat Incorporated. |
---|
2 | All rights reserved. |
---|
3 | |
---|
4 | Redistribution and use in source and binary forms, with or without |
---|
5 | modification, are permitted provided that the following conditions are met: |
---|
6 | |
---|
7 | Redistributions of source code must retain the above copyright |
---|
8 | notice, this list of conditions and the following disclaimer. |
---|
9 | |
---|
10 | Redistributions in binary form must reproduce the above copyright |
---|
11 | notice, this list of conditions and the following disclaimer in the |
---|
12 | documentation and/or other materials provided with the distribution. |
---|
13 | |
---|
14 | The name of Red Hat Incorporated may not be used to endorse |
---|
15 | or promote products derived from this software without specific |
---|
16 | prior written permission. |
---|
17 | |
---|
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
21 | ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY |
---|
22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
---|
25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
28 | */ |
---|
29 | |
---|
30 | /* |
---|
31 | FUNCTION |
---|
32 | <<towctrans>>, <<towctrans_l>>---extensible wide-character translation |
---|
33 | |
---|
34 | INDEX |
---|
35 | towctrans |
---|
36 | |
---|
37 | INDEX |
---|
38 | towctrans_l |
---|
39 | |
---|
40 | SYNOPSIS |
---|
41 | #include <wctype.h> |
---|
42 | wint_t towctrans(wint_t <[c]>, wctrans_t <[w]>); |
---|
43 | |
---|
44 | #include <wctype.h> |
---|
45 | wint_t towctrans_l(wint_t <[c]>, wctrans_t <[w]>, locale_t <[locale]>); |
---|
46 | |
---|
47 | |
---|
48 | DESCRIPTION |
---|
49 | <<towctrans>> is a function which converts wide characters based on |
---|
50 | a specified translation type <[w]>. If the translation type is |
---|
51 | invalid or cannot be applied to the current character, no change |
---|
52 | to the character is made. |
---|
53 | |
---|
54 | <<towctrans_l>> is like <<towctrans>> but performs the function based on the |
---|
55 | locale specified by the locale object locale. If <[locale]> is |
---|
56 | LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. |
---|
57 | |
---|
58 | RETURNS |
---|
59 | <<towctrans>>, <<towctrans_l>> return the translated equivalent of <[c]> |
---|
60 | when it is a valid for the given translation, otherwise, it returns the |
---|
61 | input character. When the translation type is invalid, <<errno>> is |
---|
62 | set to <<EINVAL>>. |
---|
63 | |
---|
64 | PORTABILITY |
---|
65 | <<towctrans>> is C99. |
---|
66 | <<towctrans_l>> is POSIX-1.2008. |
---|
67 | |
---|
68 | No supporting OS subroutines are required. |
---|
69 | */ |
---|
70 | |
---|
71 | #include <_ansi.h> |
---|
72 | #include <string.h> |
---|
73 | #include <reent.h> |
---|
74 | #include <wctype.h> |
---|
75 | #include <errno.h> |
---|
76 | #include "local.h" |
---|
77 | |
---|
78 | wint_t |
---|
79 | _towctrans_r (struct _reent *r, |
---|
80 | wint_t c, |
---|
81 | wctrans_t w) |
---|
82 | { |
---|
83 | if (w == WCT_TOLOWER) |
---|
84 | return towlower (c); |
---|
85 | else if (w == WCT_TOUPPER) |
---|
86 | return towupper (c); |
---|
87 | else |
---|
88 | { |
---|
89 | r->_errno = EINVAL; |
---|
90 | return c; |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | #ifndef _REENT_ONLY |
---|
95 | wint_t |
---|
96 | towctrans (wint_t c, |
---|
97 | wctrans_t w) |
---|
98 | { |
---|
99 | return _towctrans_r (_REENT, c, w); |
---|
100 | } |
---|
101 | #endif /* !_REENT_ONLY */ |
---|