OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [stdio/] [fgetwc.c] - Diff between revs 207 and 345

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

Rev 207 Rev 345
/*-
/*-
 * 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
<<fgetwc>>, <<getwc>>---get a wide character from a file or stream
<<fgetwc>>, <<getwc>>---get a wide character from a file or stream
 
 
INDEX
INDEX
        fgetwc
        fgetwc
INDEX
INDEX
        _fgetwc_r
        _fgetwc_r
INDEX
INDEX
        getwc
        getwc
INDEX
INDEX
        _getwc_r
        _getwc_r
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <stdio.h>
        #include <stdio.h>
        #include <wchar.h>
        #include <wchar.h>
        wint_t fgetwc(FILE *<[fp]>);
        wint_t fgetwc(FILE *<[fp]>);
 
 
        #include <stdio.h>
        #include <stdio.h>
        #include <wchar.h>
        #include <wchar.h>
        wint_t _fgetwc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
        wint_t _fgetwc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
 
 
        #include <stdio.h>
        #include <stdio.h>
        #include <wchar.h>
        #include <wchar.h>
        wint_t getwc(FILE *<[fp]>);
        wint_t getwc(FILE *<[fp]>);
 
 
        #include <stdio.h>
        #include <stdio.h>
        #include <wchar.h>
        #include <wchar.h>
        wint_t _getwc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
        wint_t _getwc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <stdio.h>
        #include <stdio.h>
        #include <wchar.h>
        #include <wchar.h>
        wint_t fgetwc(<[fp]>)
        wint_t fgetwc(<[fp]>)
        FILE *<[fp]>;
        FILE *<[fp]>;
 
 
        #include <stdio.h>
        #include <stdio.h>
        #include <wchar.h>
        #include <wchar.h>
        wint_t _fgetwc_r(<[ptr]>, <[fp]>)
        wint_t _fgetwc_r(<[ptr]>, <[fp]>)
        struct _reent *<[ptr]>;
        struct _reent *<[ptr]>;
        FILE *<[fp]>;
        FILE *<[fp]>;
 
 
        #include <stdio.h>
        #include <stdio.h>
        #include <wchar.h>
        #include <wchar.h>
        wint_t getwc(<[fp]>)
        wint_t getwc(<[fp]>)
        FILE *<[fp]>;
        FILE *<[fp]>;
 
 
        #include <stdio.h>
        #include <stdio.h>
        #include <wchar.h>
        #include <wchar.h>
        wint_t _getwc_r(<[ptr]>, <[fp]>)
        wint_t _getwc_r(<[ptr]>, <[fp]>)
        struct _reent *<[ptr]>;
        struct _reent *<[ptr]>;
        FILE *<[fp]>;
        FILE *<[fp]>;
 
 
DESCRIPTION
DESCRIPTION
Use <<fgetwc>> to get the next wide character from the file or stream
Use <<fgetwc>> to get the next wide character from the file or stream
identified by <[fp]>.  As a side effect, <<fgetwc>> advances the file's
identified by <[fp]>.  As a side effect, <<fgetwc>> advances the file's
current position indicator.
current position indicator.
 
 
The  <<getwc>>  function  or macro functions identically to <<fgetwc>>.  It
The  <<getwc>>  function  or macro functions identically to <<fgetwc>>.  It
may be implemented as a macro, and may evaluate its argument more  than
may be implemented as a macro, and may evaluate its argument more  than
once. There is no reason ever to use it.
once. There is no reason ever to use it.
 
 
<<_fgetwc_r>> and <<_getwc_r>> are simply reentrant versions of
<<_fgetwc_r>> and <<_getwc_r>> are simply reentrant versions of
<<fgetwc>> and <<getwc>> that are passed the additional reentrant
<<fgetwc>> and <<getwc>> that are passed the additional reentrant
structure pointer argument: <[ptr]>.
structure pointer argument: <[ptr]>.
 
 
RETURNS
RETURNS
The next wide character cast to <<wint_t>>), unless there is no more data,
The next wide character cast to <<wint_t>>), unless there is no more data,
or the host system reports a read error; in either of these situations,
or the host system reports a read error; in either of these situations,
<<fgetwc>> and <<getwc>> return <<WEOF>>.
<<fgetwc>> and <<getwc>> return <<WEOF>>.
 
 
You can distinguish the two situations that cause an <<EOF>> result by
You can distinguish the two situations that cause an <<EOF>> result by
using the <<ferror>> and <<feof>> functions.
using the <<ferror>> and <<feof>> functions.
 
 
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 <stdlib.h>
#include <stdlib.h>
#include <wchar.h>
#include <wchar.h>
#include "local.h"
#include "local.h"
 
 
static wint_t
static wint_t
_DEFUN(__fgetwc, (ptr, fp),
_DEFUN(__fgetwc, (ptr, fp),
        struct _reent *ptr _AND
        struct _reent *ptr _AND
        register FILE *fp)
        register FILE *fp)
{
{
  wchar_t wc;
  wchar_t wc;
  size_t nconv;
  size_t nconv;
 
 
  if (fp->_r <= 0 && __srefill_r (ptr, fp))
  if (fp->_r <= 0 && __srefill_r (ptr, fp))
    return (WEOF);
    return (WEOF);
  if (MB_CUR_MAX == 1)
  if (MB_CUR_MAX == 1)
    {
    {
      /* Fast path for single-byte encodings. */
      /* Fast path for single-byte encodings. */
      wc = *fp->_p++;
      wc = *fp->_p++;
      fp->_r--;
      fp->_r--;
      return (wc);
      return (wc);
    }
    }
  do
  do
    {
    {
      nconv = _mbrtowc_r (ptr, &wc, (char *) fp->_p, fp->_r, &fp->_mbstate);
      nconv = _mbrtowc_r (ptr, &wc, (char *) fp->_p, fp->_r, &fp->_mbstate);
      if (nconv == (size_t)-1)
      if (nconv == (size_t)-1)
        break;
        break;
      else if (nconv == (size_t)-2)
      else if (nconv == (size_t)-2)
        continue;
        continue;
      else if (nconv == 0)
      else if (nconv == 0)
        {
        {
          /*
          /*
           * Assume that the only valid representation of
           * Assume that the only valid representation of
           * the null wide character is a single null byte.
           * the null wide character is a single null byte.
           */
           */
          fp->_p++;
          fp->_p++;
          fp->_r--;
          fp->_r--;
          return (L'\0');
          return (L'\0');
        }
        }
      else
      else
        {
        {
          fp->_p += nconv;
          fp->_p += nconv;
          fp->_r -= nconv;
          fp->_r -= nconv;
          return (wc);
          return (wc);
        }
        }
    }
    }
  while (__srefill_r(ptr, fp) == 0);
  while (__srefill_r(ptr, fp) == 0);
  fp->_flags |= __SERR;
  fp->_flags |= __SERR;
  errno = EILSEQ;
  errno = EILSEQ;
  return (WEOF);
  return (WEOF);
}
}
 
 
wint_t
wint_t
_DEFUN(_fgetwc_r, (ptr, fp),
_DEFUN(_fgetwc_r, (ptr, fp),
        struct _reent *ptr _AND
        struct _reent *ptr _AND
        register FILE *fp)
        register FILE *fp)
{
{
  wint_t r;
  wint_t r;
 
 
  __sfp_lock_acquire ();
  __sfp_lock_acquire ();
  _flockfile (fp);
  _flockfile (fp);
  ORIENT(fp, 1);
  ORIENT(fp, 1);
  r = __fgetwc (ptr, fp);
  r = __fgetwc (ptr, fp);
  _funlockfile (fp);
  _funlockfile (fp);
  __sfp_lock_release ();
  __sfp_lock_release ();
  return r;
  return r;
}
}
 
 
wint_t
wint_t
_DEFUN(fgetwc, (fp),
_DEFUN(fgetwc, (fp),
        FILE *fp)
        FILE *fp)
{
{
  CHECK_INIT(_REENT, fp);
  CHECK_INIT(_REENT, fp);
  return _fgetwc_r (_REENT, fp);
  return _fgetwc_r (_REENT, fp);
}
}
 
 

powered by: WebSVN 2.1.0

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