summaryrefslogtreecommitdiffstats
path: root/newlib/libc/stdlib/wcrtomb.c
blob: f68533cbd6967599b546f6feb316a9851adab8b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <reent.h>
#include <errno.h>

size_t
wcrtomb(char *s, wchar_t wc, mbstate_t *ps)
{
  int retval = 0;
  _REENT_CHECK_MISC(_REENT);

  if (s == NULL)
    retval = _wctomb_r (_REENT, "", wc, ps);
  else
    retval = _wctomb_r (_REENT, s, wc, ps);

  if (retval == -1)
    {
      _REENT->_errno = EILSEQ;
      return (size_t)(-1);
    }
  else
    return (size_t)retval;
}