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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [stdlib/] [wcstombs_r.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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