Back to index

nagios-plugins  1.4.16
wcrtomb.c
Go to the documentation of this file.
00001 /* Convert wide character to multibyte character.
00002    Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
00003    Written by Bruno Haible <bruno@clisp.org>, 2008.
00004 
00005    This program is free software: you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 3 of the License, or
00008    (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00017 
00018 #include <config.h>
00019 
00020 /* Specification.  */
00021 #include <wchar.h>
00022 
00023 #include <errno.h>
00024 #include <stdlib.h>
00025 
00026 
00027 size_t
00028 wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
00029 {
00030   /* This implementation of wcrtomb on top of wctomb() supports only
00031      stateless encodings.  ps must be in the initial state.  */
00032   if (ps != NULL && !mbsinit (ps))
00033     {
00034       errno = EINVAL;
00035       return (size_t)(-1);
00036     }
00037 
00038   if (s == NULL)
00039     /* We know the NUL wide character corresponds to the NUL character.  */
00040     return 1;
00041   else
00042     {
00043       int ret = wctomb (s, wc);
00044 
00045       if (ret >= 0)
00046         return ret;
00047       else
00048         {
00049           errno = EILSEQ;
00050           return (size_t)(-1);
00051         }
00052     }
00053 }