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

Subversion Repositories openrisc

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

powered by: WebSVN 2.1.0

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