Back to index

glibc  2.9
wctomb.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 1992, 1995-1999, 2002, 2008
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library 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 GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <stdlib.h>
00021 #include <string.h>
00022 #include <wchar.h>
00023 #include <gconv.h>
00024 #include <wcsmbs/wcsmbsload.h>
00025 
00026 
00027 /* Shared with __wctomb_chk.  */
00028 mbstate_t __wctomb_state attribute_hidden;
00029 
00030 /* Convert WCHAR into its multibyte character representation,
00031    putting this in S and returning its length.
00032 
00033    Attention: this function should NEVER be intentionally used.
00034    The interface is completely stupid.  The state is shared between
00035    all conversion functions.  You should use instead the restartable
00036    version `wcrtomb'.  */
00037 int
00038 wctomb (char *s, wchar_t wchar)
00039 {
00040   /* If S is NULL the function has to return null or not null
00041      depending on the encoding having a state depending encoding or
00042      not.  */
00043   if (s == NULL)
00044     {
00045       const struct gconv_fcts *fcts;
00046 
00047       /* Get the conversion functions.  */
00048       fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));
00049 
00050       /* This is an extension in the Unix standard which does not directly
00051         violate ISO C.  */
00052       memset (&__wctomb_state, '\0', sizeof __wctomb_state);
00053 
00054       return fcts->tomb->__stateful;
00055     }
00056 
00057   return __wcrtomb (s, wchar, &__wctomb_state);
00058 }
00059 libc_hidden_def (wctomb)