xref: /netbsd-src/external/gpl3/gdb/dist/gnulib/import/btowc.c (revision 4b169a6ba595ae283ca507b26b15fdff40495b1c)
18dffb485Schristos /* Convert unibyte character to wide character.
2*4b169a6bSchristos    Copyright (C) 2008, 2010-2022 Free Software Foundation, Inc.
38dffb485Schristos    Written by Bruno Haible <bruno@clisp.org>, 2008.
48dffb485Schristos 
5*4b169a6bSchristos    This file is free software: you can redistribute it and/or modify
6*4b169a6bSchristos    it under the terms of the GNU Lesser General Public License as
7*4b169a6bSchristos    published by the Free Software Foundation; either version 2.1 of the
8*4b169a6bSchristos    License, or (at your option) any later version.
98dffb485Schristos 
10*4b169a6bSchristos    This file is distributed in the hope that it will be useful,
118dffb485Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
128dffb485Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*4b169a6bSchristos    GNU Lesser General Public License for more details.
148dffb485Schristos 
15*4b169a6bSchristos    You should have received a copy of the GNU Lesser General Public License
168dffb485Schristos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
178dffb485Schristos 
188dffb485Schristos #include <config.h>
198dffb485Schristos 
208dffb485Schristos /* Specification.  */
218dffb485Schristos #include <wchar.h>
228dffb485Schristos 
238dffb485Schristos #include <stdio.h>
248dffb485Schristos #include <stdlib.h>
258dffb485Schristos 
268dffb485Schristos wint_t
btowc(int c)278dffb485Schristos btowc (int c)
288dffb485Schristos {
298dffb485Schristos   if (c != EOF)
308dffb485Schristos     {
318dffb485Schristos       char buf[1];
328dffb485Schristos       wchar_t wc;
338dffb485Schristos 
348dffb485Schristos       buf[0] = c;
358dffb485Schristos       if (mbtowc (&wc, buf, 1) >= 0)
368dffb485Schristos         return wc;
378dffb485Schristos     }
388dffb485Schristos   return WEOF;
398dffb485Schristos }
40