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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 148 jeremybenn
#include <stdlib.h>
2
#include <wchar.h>
3
 
4
size_t
5
_DEFUN (_wcstombs_r, (reent, s, pwcs, n, state),
6
        struct _reent *r    _AND
7
        char          *s    _AND
8
        const wchar_t *pwcs _AND
9
        size_t         n    _AND
10
        mbstate_t     *state)
11
{
12
  char *ptr = s;
13
  size_t max = n;
14
  char buff[8];
15
  int i, num_to_copy;
16
 
17
  if (s == NULL)
18
    {
19
      size_t num_bytes = 0;
20
      while (*pwcs != 0)
21
         num_bytes += _wctomb_r (r, buff, *pwcs++, state);
22
      return num_bytes;
23
    }
24
  else
25
    {
26
      while (n > 0)
27
        {
28
          int bytes = _wctomb_r (r, buff, *pwcs, state);
29
          if (bytes == -1)
30
            return -1;
31
          num_to_copy = (n > bytes ? bytes : (int)n);
32
          for (i = 0; i < num_to_copy; ++i)
33
            *ptr++ = buff[i];
34
 
35
          if (*pwcs == 0x00)
36
            return ptr - s - (n >= bytes);
37
          ++pwcs;
38
          n -= num_to_copy;
39
        }
40
      return max;
41
    }
42
}

powered by: WebSVN 2.1.0

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