OSDN Git Service

Make <vptype.h> header effectively self-contained.
[mingw/mingw-org-wsl.git] / mingwrt / mingwex / btowc.c
1 /*
2  * btowc.c
3  *
4  * Implementation of an ISO-C99 conforming btowc() function; note that,
5  * since this considers only one byte for conversion, and a single byte
6  * can never convert to a surrogate pair, this is not susceptible to the
7  * potential wchar_t overflow error, which may occur with functions such
8  * as mbrtowc(), which may need to return surrogate pairs.
9  *
10  *
11  * $Id$
12  *
13  * Written by Keith Marshall <keith@users.osdn.me>
14  * Copyright (C) 2020, 2022, MinGW.OSDN Project
15  *
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining a
18  * copy of this software and associated documentation files (the "Software"),
19  * to deal in the Software without restriction, including without limitation
20  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
21  * and/or sell copies of the Software, and to permit persons to whom the
22  * Software is furnished to do so, subject to the following conditions:
23  *
24  * The above copyright notice, this permission notice, and the following
25  * disclaimer shall be included in all copies or substantial portions of
26  * the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
29  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
31  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
34  * DEALINGS IN THE SOFTWARE.
35  *
36  */
37 #include "wcharmap.h"
38
39 /* We also need <stdio.h>, for EOF.
40  */
41 #include <stdio.h>
42
43 wint_t btowc( int c )
44 { /* Implementation of ISO-C99 btowc() function, in libmingwex.a;
45    * this performs an MBCS to wchar_t conversion on the given single
46    * character argument, (expressed as an int), returning WEOF in
47    * the event that conversion fails.
48    */
49   if( c != EOF )
50   { wint_t wc_result;
51     (void)(__mingw_mbrtowc_codeset_init());
52     if( __mingw_mbtowc_convert( (char *)(&c), 1, &wc_result, 1) == 1 )
53       return wc_result;
54   }
55   return WEOF;
56 }
57
58 /* $RCSfile$: end of file */