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

Subversion Repositories openrisc

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

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 (_mbsrtowcs_r, (r, dst, src, n, ps),
10
        struct _reent *r _AND
11
        wchar_t *dst _AND
12
        const char **src _AND
13
        size_t n _AND
14
        mbstate_t *ps)
15
{
16
  wchar_t *ptr = dst;
17
  const char *tmp_src;
18
  size_t max;
19
  size_t count = 0;
20
  int bytes;
21
 
22
#ifdef _MB_CAPABLE
23
  if (ps == NULL)
24
    {
25
      _REENT_CHECK_MISC(r);
26
      ps = &(_REENT_MBSRTOWCS_STATE(r));
27
    }
28
#endif
29
 
30
  if (dst == NULL)
31
    {
32
      /* Ignore original n value and do not alter src pointer if the
33
         dst pointer is NULL.  */
34
      n = (size_t)-1;
35
      tmp_src = *src;
36
      src = &tmp_src;
37
    }
38
 
39
  max = n;
40
  while (n > 0)
41
    {
42
      bytes = _mbrtowc_r (r, ptr, *src, MB_CUR_MAX, ps);
43
      if (bytes > 0)
44
        {
45
          *src += bytes;
46
          ++count;
47
          ptr = (dst == NULL) ? NULL : ptr + 1;
48
          --n;
49
        }
50
      else if (bytes == -2)
51
        {
52
          *src += MB_CUR_MAX;
53
        }
54
      else if (bytes == 0)
55
        {
56
          *src = NULL;
57
          return count;
58
        }
59
      else
60
        {
61
          ps->__count = 0;
62
          r->_errno = EILSEQ;
63
          return (size_t)-1;
64
        }
65
    }
66
 
67
  return (size_t)max;
68
}
69
 
70
#ifndef _REENT_ONLY
71
size_t
72
_DEFUN (mbsrtowcs, (dst, src, len, ps),
73
        wchar_t *dst _AND
74
        const char **src _AND
75
        size_t len _AND
76
        mbstate_t *ps)
77
{
78
  return _mbsrtowcs_r (_REENT, dst, src, len, ps);
79
}
80
#endif /* !_REENT_ONLY */

powered by: WebSVN 2.1.0

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