Blame stdlib/wctomb.c

Packit Service 82fcde
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <stdlib.h>
Packit Service 82fcde
#include <string.h>
Packit Service 82fcde
#include <wchar.h>
Packit Service 82fcde
#include <gconv.h>
Packit Service 82fcde
#include <wcsmbs/wcsmbsload.h>
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* Shared with __wctomb_chk.  */
Packit Service 82fcde
mbstate_t __wctomb_state attribute_hidden;
Packit Service 82fcde
Packit Service 82fcde
/* Convert WCHAR into its multibyte character representation,
Packit Service 82fcde
   putting this in S and returning its length.
Packit Service 82fcde
Packit Service 82fcde
   Attention: this function should NEVER be intentionally used.
Packit Service 82fcde
   The interface is completely stupid.  The state is shared between
Packit Service 82fcde
   all conversion functions.  You should use instead the restartable
Packit Service 82fcde
   version `wcrtomb'.  */
Packit Service 82fcde
int
Packit Service 82fcde
wctomb (char *s, wchar_t wchar)
Packit Service 82fcde
{
Packit Service 82fcde
  /* If S is NULL the function has to return null or not null
Packit Service 82fcde
     depending on the encoding having a state depending encoding or
Packit Service 82fcde
     not.  */
Packit Service 82fcde
  if (s == NULL)
Packit Service 82fcde
    {
Packit Service 82fcde
      const struct gconv_fcts *fcts;
Packit Service 82fcde
Packit Service 82fcde
      /* Get the conversion functions.  */
Packit Service 82fcde
      fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));
Packit Service 82fcde
Packit Service 82fcde
      /* This is an extension in the Unix standard which does not directly
Packit Service 82fcde
	 violate ISO C.  */
Packit Service 82fcde
      memset (&__wctomb_state, '\0', sizeof __wctomb_state);
Packit Service 82fcde
Packit Service 82fcde
      return fcts->tomb->__stateful;
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  return __wcrtomb (s, wchar, &__wctomb_state);
Packit Service 82fcde
}
Packit Service 82fcde
libc_hidden_def (wctomb)