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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [stdio/] [fpurge.c] - Blame information for rev 207

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/* Copyright (C) 2009 Eric Blake
2
 * Permission to use, copy, modify, and distribute this software
3
 * is freely granted, provided that this notice is preserved.
4
 */
5
 
6
/*
7
FUNCTION
8
<<fpurge>>---discard pending file I/O
9
 
10
INDEX
11
        fpurge
12
INDEX
13
        _fpurge_r
14
 
15
ANSI_SYNOPSIS
16
        #include <stdio.h>
17
        int fpurge(FILE *<[fp]>);
18
 
19
        int _fpurge_r(struct _reent *<[reent]>, FILE *<[fp]>);
20
 
21
DESCRIPTION
22
Use <<fpurge>> to clear all buffers of the given stream.  For output
23
streams, this discards data not yet written to disk.  For input streams,
24
this discards any data from <<ungetc>> and any data retrieved from disk
25
but not yet read via <<getc>>.  This is more severe than <<fflush>>,
26
and generally is only needed when manually altering the underlying file
27
descriptor of a stream.
28
 
29
The alternate function <<_fpurge_r>> is a reentrant version, where the
30
extra argument <[reent]> is a pointer to a reentrancy structure, and
31
<[fp]> must not be NULL.
32
 
33
RETURNS
34
<<fpurge>> returns <<0>> unless <[fp]> is not valid, in which case it
35
returns <<EOF>> and sets <<errno>>.
36
 
37
PORTABILITY
38
These functions are not portable to any standard.
39
 
40
No supporting OS subroutines are required.
41
*/
42
 
43
#include <_ansi.h>
44
#include <stdio.h>
45
#include <errno.h>
46
#include "local.h"
47
 
48
/* Discard I/O from a single file.  */
49
 
50
int
51
_DEFUN(_fpurge_r, (ptr, fp),
52
       struct _reent *ptr _AND
53
       register FILE * fp)
54
{
55
  int t;
56
 
57
  CHECK_INIT (ptr, fp);
58
 
59
  _flockfile (fp);
60
 
61
  t = fp->_flags;
62
  if (!t)
63
    {
64
      ptr->_errno = EBADF;
65
      _funlockfile (fp);
66
      return EOF;
67
    }
68
  fp->_p = fp->_bf._base;
69
  if ((t & __SWR) == 0)
70
    {
71
      fp->_r = 0;
72
      if (HASUB (fp))
73
        FREEUB (ptr, fp);
74
    }
75
  else
76
    fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size;
77
  _funlockfile (fp);
78
  return 0;
79
}
80
 
81
#ifndef _REENT_ONLY
82
 
83
int
84
_DEFUN(fpurge, (fp),
85
       register FILE * fp)
86
{
87
  return _fpurge_r (_REENT, fp);
88
}
89
 
90
#endif /* _REENT_ONLY */

powered by: WebSVN 2.1.0

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