source: trunk/libs/newlib/src/newlib/libc/stdio/fpurge.c @ 577

Last change on this file since 577 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.1 KB
Line 
1/* 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/*
7FUNCTION
8<<fpurge>>---discard pending file I/O
9
10INDEX
11        fpurge
12INDEX
13        _fpurge_r
14INDEX
15        __fpurge
16
17SYNOPSIS
18        #include <stdio.h>
19        int fpurge(FILE *<[fp]>);
20
21        int _fpurge_r(struct _reent *<[reent]>, FILE *<[fp]>);
22
23        #include <stdio.h>
24        #include <stdio_ext.h>
25        void  __fpurge(FILE *<[fp]>);
26
27
28DESCRIPTION
29Use <<fpurge>> to clear all buffers of the given stream.  For output
30streams, this discards data not yet written to disk.  For input streams,
31this discards any data from <<ungetc>> and any data retrieved from disk
32but not yet read via <<getc>>.  This is more severe than <<fflush>>,
33and generally is only needed when manually altering the underlying file
34descriptor of a stream.
35
36<<__fpurge>> behaves exactly like <<fpurge>> but does not return a value.
37
38The alternate function <<_fpurge_r>> is a reentrant version, where the
39extra argument <[reent]> is a pointer to a reentrancy structure, and
40<[fp]> must not be NULL.
41
42RETURNS
43<<fpurge>> returns <<0>> unless <[fp]> is not valid, in which case it
44returns <<EOF>> and sets <<errno>>.
45
46PORTABILITY
47These functions are not portable to any standard.
48
49No supporting OS subroutines are required.
50*/
51
52#include <_ansi.h>
53#include <stdio.h>
54#ifndef __rtems__
55#include <stdio_ext.h>
56#endif
57#include <errno.h>
58#include "local.h"
59
60/* Discard I/O from a single file.  */
61
62int
63_fpurge_r (struct _reent *ptr,
64       register FILE * fp)
65{
66  int t;
67
68  CHECK_INIT (ptr, fp);
69
70  _newlib_flockfile_start (fp);
71
72  t = fp->_flags;
73  if (!t)
74    {
75      ptr->_errno = EBADF;
76      _newlib_flockfile_exit (fp);
77      return EOF;
78    }
79  fp->_p = fp->_bf._base;
80  if ((t & __SWR) == 0)
81    {
82      fp->_r = 0;
83      if (HASUB (fp))
84        FREEUB (ptr, fp);
85    }
86  else
87    fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size;
88  _newlib_flockfile_end (fp);
89  return 0;
90}
91
92#ifndef _REENT_ONLY
93
94int
95fpurge (register FILE * fp)
96{
97  return _fpurge_r (_REENT, fp);
98}
99
100#ifndef __rtems__
101
102void
103__fpurge (register FILE * fp)
104{
105  _fpurge_r (_REENT, fp);
106}
107
108#endif
109
110#endif /* _REENT_ONLY */
Note: See TracBrowser for help on using the repository browser.