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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc2/] [newlib/] [libc/] [stdlib/] [wcstombs_r.c] - Diff between revs 207 and 520

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 520
#include <stdlib.h>
#include <stdlib.h>
#include <wchar.h>
#include <wchar.h>
#include "local.h"
#include "local.h"
 
 
size_t
size_t
_DEFUN (_wcstombs_r, (reent, s, pwcs, n, state),
_DEFUN (_wcstombs_r, (reent, s, pwcs, n, state),
        struct _reent *r    _AND
        struct _reent *r    _AND
        char          *s    _AND
        char          *s    _AND
        const wchar_t *pwcs _AND
        const wchar_t *pwcs _AND
        size_t         n    _AND
        size_t         n    _AND
        mbstate_t     *state)
        mbstate_t     *state)
{
{
  char *ptr = s;
  char *ptr = s;
  size_t max = n;
  size_t max = n;
  char buff[8];
  char buff[8];
  int i, num_to_copy;
  int i, num_to_copy;
 
 
  if (s == NULL)
  if (s == NULL)
    {
    {
      size_t num_bytes = 0;
      size_t num_bytes = 0;
      while (*pwcs != 0)
      while (*pwcs != 0)
         num_bytes += __wctomb (r, buff, *pwcs++, __locale_charset (), state);
         num_bytes += __wctomb (r, buff, *pwcs++, __locale_charset (), state);
      return num_bytes;
      return num_bytes;
    }
    }
  else
  else
    {
    {
      while (n > 0)
      while (n > 0)
        {
        {
          int bytes = __wctomb (r, buff, *pwcs, __locale_charset (), state);
          int bytes = __wctomb (r, buff, *pwcs, __locale_charset (), state);
          if (bytes == -1)
          if (bytes == -1)
            return -1;
            return -1;
          num_to_copy = (n > bytes ? bytes : (int)n);
          num_to_copy = (n > bytes ? bytes : (int)n);
          for (i = 0; i < num_to_copy; ++i)
          for (i = 0; i < num_to_copy; ++i)
            *ptr++ = buff[i];
            *ptr++ = buff[i];
 
 
          if (*pwcs == 0x00)
          if (*pwcs == 0x00)
            return ptr - s - (n >= bytes);
            return ptr - s - (n >= bytes);
          ++pwcs;
          ++pwcs;
          n -= num_to_copy;
          n -= num_to_copy;
        }
        }
      return max;
      return max;
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

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