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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [stdio/] [fflush.c] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
/*
2
 * Copyright (c) 1990 The Regents of the University of California.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms are permitted
6
 * provided that the above copyright notice and this paragraph are
7
 * duplicated in all such forms and that any documentation,
8
 * advertising materials, and other materials related to such
9
 * distribution and use acknowledge that the software was developed
10
 * by the University of California, Berkeley.  The name of the
11
 * University may not be used to endorse or promote products derived
12
 * from this software without specific prior written permission.
13
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
 
18
/*
19
FUNCTION
20
<<fflush>>---flush buffered file output
21
 
22
INDEX
23
        fflush
24
 
25
ANSI_SYNOPSIS
26
        #include <stdio.h>
27
        int fflush(FILE *<[fp]>);
28
 
29
TRAD_SYNOPSIS
30
        #include <stdio.h>
31
        int fflush(<[fp]>)
32
        FILE *<[fp]>;
33
 
34
DESCRIPTION
35
The <<stdio>> output functions can buffer output before delivering it
36
to the host system, in order to minimize the overhead of system calls.
37
 
38
Use <<fflush>> to deliver any such pending output (for the file
39
or stream identified by <[fp]>) to the host system.
40
 
41
If <[fp]> is <<NULL>>, <<fflush>> delivers pending output from all
42
open files.
43
 
44
RETURNS
45
<<fflush>> returns <<0>> unless it encounters a write error; in that
46
situation, it returns <<EOF>>.
47
 
48
PORTABILITY
49
ANSI C requires <<fflush>>.
50
 
51
No supporting OS subroutines are required.
52
*/
53
 
54
#include <stdio.h>
55
#include "local.h"
56
 
57
/* Flush a single file, or (if fp is NULL) all files.  */
58
 
59
int
60
_DEFUN (fflush, (fp),
61
        register FILE * fp)
62
{
63
  register unsigned char *p;
64
  register int n, t;
65
 
66
 
67
 
68
 
69
  if (fp == NULL)
70
    return _fwalk (_REENT, fflush);
71
 
72
  CHECK_INIT (fp);
73
 
74
  t = fp->_flags;
75
  if ((t & __SWR) == 0 || (p = fp->_bf._base) == NULL)
76
    return 0;
77
  n = fp->_p - p;               /* write this much */
78
 
79
  /*
80
   * Set these immediately to avoid problems with longjmp
81
   * and to allow exchange buffering (via setvbuf) in user
82
   * write function.
83
   */
84
  fp->_p = p;
85
  fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size;
86
 
87
  while (n > 0)
88
    {
89
      t = (*fp->_write) (fp->_cookie, (char *) p, n);
90
      if (t <= 0)
91
        {
92
          fp->_flags |= __SERR;
93
          return EOF;
94
        }
95
      p += t;
96
      n -= t;
97
    }
98
  return 0;
99
}

powered by: WebSVN 2.1.0

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