Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fpurge.c « stdio « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: acd177a696bc3710b15b8c64464aae2ae2d106dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Copyright (C) 2009 Eric Blake
 * Permission to use, copy, modify, and distribute this software
 * is freely granted, provided that this notice is preserved.
 */

/*
FUNCTION
<<fpurge>>---discard pending file I/O

INDEX
	fpurge
INDEX
	_fpurge_r
INDEX
	__fpurge

SYNOPSIS
	#include <stdio.h>
	int fpurge(FILE *<[fp]>);

	int _fpurge_r(struct _reent *<[reent]>, FILE *<[fp]>);

	#include <stdio.h>
	#include <stdio_ext.h>
	void  __fpurge(FILE *<[fp]>);


DESCRIPTION
Use <<fpurge>> to clear all buffers of the given stream.  For output
streams, this discards data not yet written to disk.  For input streams,
this discards any data from <<ungetc>> and any data retrieved from disk
but not yet read via <<getc>>.  This is more severe than <<fflush>>,
and generally is only needed when manually altering the underlying file
descriptor of a stream.

<<__fpurge>> behaves exactly like <<fpurge>> but does not return a value.

The alternate function <<_fpurge_r>> is a reentrant version, where the
extra argument <[reent]> is a pointer to a reentrancy structure, and
<[fp]> must not be NULL.

RETURNS
<<fpurge>> returns <<0>> unless <[fp]> is not valid, in which case it
returns <<EOF>> and sets <<errno>>.

PORTABILITY
These functions are not portable to any standard.

No supporting OS subroutines are required.
*/

#include <_ansi.h>
#include <stdio.h>
#ifndef __rtems__
#include <stdio_ext.h>
#endif
#include <errno.h>
#include "local.h"

/* Discard I/O from a single file.  */

int
_DEFUN(_fpurge_r, (ptr, fp),
       struct _reent *ptr,
       register FILE * fp)
{
  int t;

  CHECK_INIT (ptr, fp);

  _newlib_flockfile_start (fp);

  t = fp->_flags;
  if (!t)
    {
      ptr->_errno = EBADF;
      _newlib_flockfile_exit (fp);
      return EOF;
    }
  fp->_p = fp->_bf._base;
  if ((t & __SWR) == 0)
    {
      fp->_r = 0;
      if (HASUB (fp))
	FREEUB (ptr, fp);
    }
  else
    fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size;
  _newlib_flockfile_end (fp);
  return 0;
}

#ifndef _REENT_ONLY

int
_DEFUN(fpurge, (fp),
       register FILE * fp)
{
  return _fpurge_r (_REENT, fp);
}

#ifndef __rtems__

void
_DEFUN(__fpurge, (fp),
       register FILE * fp)
{
  _fpurge_r (_REENT, fp);
}

#endif

#endif /* _REENT_ONLY */