OSDN Git Service

Discontinue use of Microsoft's MBCS/wide character converters.
[mingw/mingw-org-wsl.git] / mingwrt / mingwex / wctob.c
1 /*
2  * wctob.c
3  *
4  * Implementation of ISO-C99 wctob() function, supporting it on legacy
5  * Windows versions, for which MSVCRT.DLL doesn't provide it, and also
6  * replacing the Microsoft implementation, on Windows versions with an
7  * MSVCRT.DLL, or MSVCRn.DLL which does.
8  *
9  *
10  * $Id$
11  *
12  * Written by Keith Marshall <keith@users.osdn.me>
13  * Copyright (C) 2020, MinGW.org Project
14  *
15  *
16  * Permission is hereby granted, free of charge, to any person obtaining a
17  * copy of this software and associated documentation files (the "Software"),
18  * to deal in the Software without restriction, including without limitation
19  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20  * and/or sell copies of the Software, and to permit persons to whom the
21  * Software is furnished to do so, subject to the following conditions:
22  *
23  * The above copyright notice, this permission notice, and the following
24  * disclaimer shall be included in all copies or substantial portions of
25  * the Software.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
28  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
30  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
33  * DEALINGS IN THE SOFTWARE.
34  *
35  */
36 #include "wcharmap.h"
37
38 #include <stdio.h>
39
40 int wctob( wint_t wc )
41 { /* Implementation of ISO-C99 wctob() function, in libmingwex.a;
42    * after first storing the effective codeset index, this performs
43    * a wchar_t to MBCS conversion on the given single wide character
44    * argument, capturing the conversion into a local buffer, checks
45    * that the result occupies exactly one byte, for which the byte
46    * value is coerced to int and returned; otherwise returns EOF.
47    */
48   (void)(__mingw_wctomb_codeset_init());
49   union { unsigned char u; char c; } retval;
50   return (__mingw_wctomb_convert( &retval.c, 1, &wc, 1 ) == 1)
51     ? (int)(retval.u) : EOF;
52 }
53
54 /* FIXME: these aliases are provided for link-compatibitity with
55  * libraries compiled against mingwrt-5.3.x; they may be removed
56  * from future versions of mingwrt.
57  */
58 int __msvcrt_wctob( wint_t )__attribute__((__weak__,__alias__("wctob")));
59 int __mingw_wctob( wint_t )__attribute__((__weak__,__alias__("wctob")));
60
61 /* $RCSfile$: end of file */