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/] [fpurge.c] - Diff between revs 207 and 345

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

Rev 207 Rev 345
/* Copyright (C) 2009 Eric Blake
/* Copyright (C) 2009 Eric Blake
 * Permission to use, copy, modify, and distribute this software
 * Permission to use, copy, modify, and distribute this software
 * is freely granted, provided that this notice is preserved.
 * is freely granted, provided that this notice is preserved.
 */
 */
 
 
/*
/*
FUNCTION
FUNCTION
<<fpurge>>---discard pending file I/O
<<fpurge>>---discard pending file I/O
 
 
INDEX
INDEX
        fpurge
        fpurge
INDEX
INDEX
        _fpurge_r
        _fpurge_r
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <stdio.h>
        #include <stdio.h>
        int fpurge(FILE *<[fp]>);
        int fpurge(FILE *<[fp]>);
 
 
        int _fpurge_r(struct _reent *<[reent]>, FILE *<[fp]>);
        int _fpurge_r(struct _reent *<[reent]>, FILE *<[fp]>);
 
 
DESCRIPTION
DESCRIPTION
Use <<fpurge>> to clear all buffers of the given stream.  For output
Use <<fpurge>> to clear all buffers of the given stream.  For output
streams, this discards data not yet written to disk.  For input streams,
streams, this discards data not yet written to disk.  For input streams,
this discards any data from <<ungetc>> and any data retrieved from disk
this discards any data from <<ungetc>> and any data retrieved from disk
but not yet read via <<getc>>.  This is more severe than <<fflush>>,
but not yet read via <<getc>>.  This is more severe than <<fflush>>,
and generally is only needed when manually altering the underlying file
and generally is only needed when manually altering the underlying file
descriptor of a stream.
descriptor of a stream.
 
 
The alternate function <<_fpurge_r>> is a reentrant version, where the
The alternate function <<_fpurge_r>> is a reentrant version, where the
extra argument <[reent]> is a pointer to a reentrancy structure, and
extra argument <[reent]> is a pointer to a reentrancy structure, and
<[fp]> must not be NULL.
<[fp]> must not be NULL.
 
 
RETURNS
RETURNS
<<fpurge>> returns <<0>> unless <[fp]> is not valid, in which case it
<<fpurge>> returns <<0>> unless <[fp]> is not valid, in which case it
returns <<EOF>> and sets <<errno>>.
returns <<EOF>> and sets <<errno>>.
 
 
PORTABILITY
PORTABILITY
These functions are not portable to any standard.
These functions are not portable to any standard.
 
 
No supporting OS subroutines are required.
No supporting OS subroutines are required.
*/
*/
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <stdio.h>
#include <stdio.h>
#include <errno.h>
#include <errno.h>
#include "local.h"
#include "local.h"
 
 
/* Discard I/O from a single file.  */
/* Discard I/O from a single file.  */
 
 
int
int
_DEFUN(_fpurge_r, (ptr, fp),
_DEFUN(_fpurge_r, (ptr, fp),
       struct _reent *ptr _AND
       struct _reent *ptr _AND
       register FILE * fp)
       register FILE * fp)
{
{
  int t;
  int t;
 
 
  CHECK_INIT (ptr, fp);
  CHECK_INIT (ptr, fp);
 
 
  _flockfile (fp);
  _flockfile (fp);
 
 
  t = fp->_flags;
  t = fp->_flags;
  if (!t)
  if (!t)
    {
    {
      ptr->_errno = EBADF;
      ptr->_errno = EBADF;
      _funlockfile (fp);
      _funlockfile (fp);
      return EOF;
      return EOF;
    }
    }
  fp->_p = fp->_bf._base;
  fp->_p = fp->_bf._base;
  if ((t & __SWR) == 0)
  if ((t & __SWR) == 0)
    {
    {
      fp->_r = 0;
      fp->_r = 0;
      if (HASUB (fp))
      if (HASUB (fp))
        FREEUB (ptr, fp);
        FREEUB (ptr, fp);
    }
    }
  else
  else
    fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size;
    fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size;
  _funlockfile (fp);
  _funlockfile (fp);
  return 0;
  return 0;
}
}
 
 
#ifndef _REENT_ONLY
#ifndef _REENT_ONLY
 
 
int
int
_DEFUN(fpurge, (fp),
_DEFUN(fpurge, (fp),
       register FILE * fp)
       register FILE * fp)
{
{
  return _fpurge_r (_REENT, fp);
  return _fpurge_r (_REENT, fp);
}
}
 
 
#endif /* _REENT_ONLY */
#endif /* _REENT_ONLY */
 
 

powered by: WebSVN 2.1.0

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