OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [stdlib/] [wcsrtombs.c] - Blame information for rev 826

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
#include <reent.h>
2
#include <newlib.h>
3
#include <wchar.h>
4
#include <stdlib.h>
5
#include <stdio.h>
6
#include <errno.h>
7
 
8
size_t
9
_DEFUN (_wcsrtombs_r, (r, dst, src, len, ps),
10
        struct _reent *r _AND
11
        char *dst _AND
12
        const wchar_t **src _AND
13
        size_t len _AND
14
        mbstate_t *ps)
15
{
16
  char *ptr = dst;
17
  char buff[10];
18
  wchar_t *pwcs;
19
  size_t n;
20
  int i;
21
 
22
#ifdef _MB_CAPABLE
23
  if (ps == NULL)
24
    {
25
      _REENT_CHECK_MISC(r);
26
      ps = &(_REENT_WCSRTOMBS_STATE(r));
27
    }
28
#endif
29
 
30
  /* If no dst pointer, treat len as maximum possible value. */
31
  if (dst == NULL)
32
    len = (size_t)-1;
33
 
34
  n = 0;
35
  pwcs = (wchar_t *)(*src);
36
 
37
  while (n < len)
38
    {
39
      int count = ps->__count;
40
      wint_t wch = ps->__value.__wch;
41
      int bytes = _wcrtomb_r (r, buff, *pwcs, ps);
42
      if (bytes == -1)
43
        {
44
          r->_errno = EILSEQ;
45
          ps->__count = 0;
46
          return (size_t)-1;
47
        }
48
      if (n + bytes <= len)
49
        {
50
          n += bytes;
51
          if (dst)
52
            {
53
              for (i = 0; i < bytes; ++i)
54
                *ptr++ = buff[i];
55
              ++(*src);
56
            }
57
          if (*pwcs++ == 0x00)
58
            {
59
              if (dst)
60
                *src = NULL;
61
              ps->__count = 0;
62
              return n - 1;
63
            }
64
        }
65
      else
66
        {
67
          /* not enough room, we must back up state to before _wctomb_r call */
68
          ps->__count = count;
69
          ps->__value.__wch = wch;
70
          len = 0;
71
        }
72
    }
73
 
74
  return n;
75
}
76
 
77
#ifndef _REENT_ONLY
78
size_t
79
_DEFUN (wcsrtombs, (dst, src, len, ps),
80
        char *dst _AND
81
        const wchar_t **src _AND
82
        size_t len _AND
83
        mbstate_t *ps)
84
{
85
  return _wcsrtombs_r (_REENT, dst, src, len, ps);
86
}
87
#endif /* !_REENT_ONLY */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.