source: trunk/libs/newlib/src/newlib/libc/stdlib/wcrtomb.c @ 567

Last change on this file since 567 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.3 KB
Line 
1#include <reent.h>
2#include <newlib.h>
3#include <wchar.h>
4#include <stdlib.h>
5#include <stdio.h>
6#include <errno.h>
7#include "local.h"
8
9size_t
10_wcrtomb_r (struct _reent *ptr,
11        char *s,
12        wchar_t wc,
13        mbstate_t *ps)
14{
15  int retval = 0;
16  char buf[10];
17
18#ifdef _MB_CAPABLE
19  if (ps == NULL)
20    {
21      _REENT_CHECK_MISC(ptr);
22      ps = &(_REENT_WCRTOMB_STATE(ptr));
23    }
24#endif
25
26  if (s == NULL)
27    retval = __WCTOMB (ptr, buf, L'\0', ps);
28  else
29    retval = __WCTOMB (ptr, s, wc, ps);
30
31  if (retval == -1)
32    {
33      ps->__count = 0;
34      ptr->_errno = EILSEQ;
35      return (size_t)(-1);
36    }
37  else
38    return (size_t)retval;
39}
40
41#ifndef _REENT_ONLY
42size_t
43wcrtomb (char *__restrict s,
44        wchar_t wc,
45        mbstate_t *__restrict ps)
46{
47#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
48  return _wcrtomb_r (_REENT, s, wc, ps);
49#else
50  int retval = 0;
51  struct _reent *reent = _REENT;
52  char buf[10];
53
54#ifdef _MB_CAPABLE
55  if (ps == NULL)
56    {
57      _REENT_CHECK_MISC(reent);
58      ps = &(_REENT_WCRTOMB_STATE(reent));
59    }
60#endif
61
62  if (s == NULL)
63    retval = __WCTOMB (reent, buf, L'\0', ps);
64  else
65    retval = __WCTOMB (reent, s, wc, ps);
66
67  if (retval == -1)
68    {
69      ps->__count = 0;
70      reent->_errno = EILSEQ;
71      return (size_t)(-1);
72    }
73  else
74    return (size_t)retval;
75#endif /* not PREFER_SIZE_OVER_SPEED */
76}
77#endif /* !_REENT_ONLY */
Note: See TracBrowser for help on using the repository browser.