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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [stdio/] [fgetws.c] - Diff between revs 148 and 158

Only display areas with differences | Details | Blame | View Log

Rev 148 Rev 158
/*-
/*-
 * Copyright (c) 2002-2004 Tim J. Robbins.
 * Copyright (c) 2002-2004 Tim J. Robbins.
 * All rights reserved.
 * All rights reserved.
 *
 *
 * Redistribution and use in source and binary forms, with or without
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * modification, are permitted provided that the following conditions
 * are met:
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *    documentation and/or other materials provided with the distribution.
 *
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * SUCH DAMAGE.
 */
 */
 
 
/*
/*
FUNCTION
FUNCTION
<<fgetws>>---get wide character string from a file or stream
<<fgetws>>---get wide character string from a file or stream
 
 
INDEX
INDEX
        fgetws
        fgetws
INDEX
INDEX
        _fgetws_r
        _fgetws_r
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <wchar.h>
        #include <wchar.h>
        wchar_t *fgetws(wchar_t *<[ws]>, int <[n]>, FILE *<[fp]>);
        wchar_t *fgetws(wchar_t *<[ws]>, int <[n]>, FILE *<[fp]>);
 
 
        #include <wchar.h>
        #include <wchar.h>
        wchar_t *_fgetws_r(struct _reent *<[ptr]>, wchar_t *<[ws]>, int <[n]>, FILE *<[fp]>);
        wchar_t *_fgetws_r(struct _reent *<[ptr]>, wchar_t *<[ws]>, int <[n]>, FILE *<[fp]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <wchar.h>
        #include <wchar.h>
        wchar_t *fgetws(<[ws]>,<[n]>,<[fp]>)
        wchar_t *fgetws(<[ws]>,<[n]>,<[fp]>)
        wchar_t *<[ws]>;
        wchar_t *<[ws]>;
        int <[n]>;
        int <[n]>;
        FILE *<[fp]>;
        FILE *<[fp]>;
 
 
        #include <wchar.h>
        #include <wchar.h>
        wchar_t *_fgetws_r(<[ptr]>, <[ws]>,<[n]>,<[fp]>)
        wchar_t *_fgetws_r(<[ptr]>, <[ws]>,<[n]>,<[fp]>)
        struct _reent *<[ptr]>;
        struct _reent *<[ptr]>;
        wchar_t *<[ws]>;
        wchar_t *<[ws]>;
        int <[n]>;
        int <[n]>;
        FILE *<[fp]>;
        FILE *<[fp]>;
 
 
DESCRIPTION
DESCRIPTION
Reads at most <[n-1]> wide characters from <[fp]> until a newline
Reads at most <[n-1]> wide characters from <[fp]> until a newline
is found. The wide characters including to the newline are stored
is found. The wide characters including to the newline are stored
in <[ws]>. The buffer is terminated with a 0.
in <[ws]>. The buffer is terminated with a 0.
 
 
The <<_fgetws_r>> function is simply the reentrant version of
The <<_fgetws_r>> function is simply the reentrant version of
<<fgetws>> and is passed an additional reentrancy structure
<<fgetws>> and is passed an additional reentrancy structure
pointer: <[ptr]>.
pointer: <[ptr]>.
 
 
RETURNS
RETURNS
<<fgetws>> returns the buffer passed to it, with the data
<<fgetws>> returns the buffer passed to it, with the data
filled in. If end of file occurs with some data already
filled in. If end of file occurs with some data already
accumulated, the data is returned with no other indication. If
accumulated, the data is returned with no other indication. If
no data are read, NULL is returned instead.
no data are read, NULL is returned instead.
 
 
PORTABILITY
PORTABILITY
C99, POSIX.1-2001
C99, POSIX.1-2001
*/
*/
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <reent.h>
#include <reent.h>
#include <errno.h>
#include <errno.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <wchar.h>
#include <wchar.h>
#include "local.h"
#include "local.h"
 
 
wchar_t *
wchar_t *
_DEFUN(_fgetws_r, (ptr, ws, n, fp),
_DEFUN(_fgetws_r, (ptr, ws, n, fp),
        struct _reent *ptr _AND
        struct _reent *ptr _AND
        wchar_t * ws _AND
        wchar_t * ws _AND
        int n _AND
        int n _AND
        FILE * fp)
        FILE * fp)
{
{
  wchar_t *wsp;
  wchar_t *wsp;
  size_t nconv;
  size_t nconv;
  const char *src;
  const char *src;
  unsigned char *nl;
  unsigned char *nl;
 
 
  _flockfile (fp);
  _flockfile (fp);
  ORIENT (fp, 1);
  ORIENT (fp, 1);
 
 
  if (n <= 0)
  if (n <= 0)
    {
    {
      errno = EINVAL;
      errno = EINVAL;
      goto error;
      goto error;
    }
    }
 
 
  if (fp->_r <= 0 && __srefill_r (ptr, fp))
  if (fp->_r <= 0 && __srefill_r (ptr, fp))
    /* EOF */
    /* EOF */
    goto error;
    goto error;
  wsp = ws;
  wsp = ws;
  do
  do
    {
    {
      src = fp->_p;
      src = fp->_p;
      nl = memchr (fp->_p, '\n', fp->_r);
      nl = memchr (fp->_p, '\n', fp->_r);
      nconv = _mbsrtowcs_r (ptr, wsp, &src,
      nconv = _mbsrtowcs_r (ptr, wsp, &src,
                            nl != NULL ? (nl - fp->_p + 1) : fp->_r,
                            nl != NULL ? (nl - fp->_p + 1) : fp->_r,
                            &fp->_mbstate);
                            &fp->_mbstate);
      if (nconv == (size_t) -1)
      if (nconv == (size_t) -1)
        /* Conversion error */
        /* Conversion error */
        goto error;
        goto error;
      if (src == NULL)
      if (src == NULL)
        {
        {
          /*
          /*
           * We hit a null byte. Increment the character count,
           * We hit a null byte. Increment the character count,
           * since mbsnrtowcs()'s return value doesn't include
           * since mbsnrtowcs()'s return value doesn't include
           * the terminating null, then resume conversion
           * the terminating null, then resume conversion
           * after the null.
           * after the null.
           */
           */
          nconv++;
          nconv++;
          src = memchr (fp->_p, '\0', fp->_r);
          src = memchr (fp->_p, '\0', fp->_r);
          src++;
          src++;
        }
        }
      fp->_r -= (unsigned char *) src - fp->_p;
      fp->_r -= (unsigned char *) src - fp->_p;
      fp->_p = (unsigned char *) src;
      fp->_p = (unsigned char *) src;
      n -= nconv;
      n -= nconv;
      wsp += nconv;
      wsp += nconv;
    }
    }
  while (wsp[-1] != L'\n' && n > 1 && (fp->_r > 0
  while (wsp[-1] != L'\n' && n > 1 && (fp->_r > 0
         || __srefill_r (ptr, fp) == 0));
         || __srefill_r (ptr, fp) == 0));
  if (wsp == ws)
  if (wsp == ws)
    /* EOF */
    /* EOF */
    goto error;
    goto error;
  if (!mbsinit (&fp->_mbstate))
  if (!mbsinit (&fp->_mbstate))
    /* Incomplete character */
    /* Incomplete character */
    goto error;
    goto error;
  *wsp++ = L'\0';
  *wsp++ = L'\0';
  _funlockfile (fp);
  _funlockfile (fp);
  return ws;
  return ws;
 
 
error:
error:
  _funlockfile (fp);
  _funlockfile (fp);
  return NULL;
  return NULL;
}
}
 
 
wchar_t *
wchar_t *
_DEFUN(fgetws, (ws, n, fp),
_DEFUN(fgetws, (ws, n, fp),
        wchar_t *ws _AND
        wchar_t *ws _AND
        int n _AND
        int n _AND
        FILE *fp)
        FILE *fp)
{
{
  CHECK_INIT (_REENT, fp);
  CHECK_INIT (_REENT, fp);
  return _fgetws_r (_REENT, ws, n, fp);
  return _fgetws_r (_REENT, ws, n, fp);
}
}
 
 

powered by: WebSVN 2.1.0

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