1FFLUSH(3P)                 POSIX Programmer's Manual                FFLUSH(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       fflush — flush a stream
14

SYNOPSIS

16       #include <stdio.h>
17
18       int fflush(FILE *stream);
19

DESCRIPTION

21       The functionality described on this reference page is aligned with  the
22       ISO C  standard.  Any  conflict between the requirements described here
23       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2008
24       defers to the ISO C standard.
25
26       If  stream  points to an output stream or an update stream in which the
27       most recent operation was not input, fflush() shall cause any unwritten
28       data for that stream to be written to the file, and the last data modi‐
29       fication and last file status change timestamps of the underlying  file
30       shall be marked for update.
31
32       If  stream  is  a  null  pointer,  fflush() shall perform this flushing
33       action on all streams for which the behavior is defined above.
34
35       For a stream open for reading, if the file is not already at  EOF,  and
36       the  file  is one capable of seeking, the file offset of the underlying
37       open file description shall be set to the file position of the  stream,
38       and any characters pushed back onto the stream by ungetc() or ungetwc()
39       that have not subsequently been read from the stream shall be discarded
40       (without further changing the file offset).
41

RETURN VALUE

43       Upon  successful  completion,  fflush()  shall  return 0; otherwise, it
44       shall set the error indicator for the stream, return EOF, and set errno
45       to indicate the error.
46

ERRORS

48       The fflush() function shall fail if:
49
50       EAGAIN The  O_NONBLOCK  flag  is set for the file descriptor underlying
51              stream and the thread would be delayed in the write operation.
52
53       EBADF  The file descriptor underlying stream is not valid.
54
55       EFBIG  An attempt was made to write a file  that  exceeds  the  maximum
56              file size.
57
58       EFBIG  An  attempt  was made to write a file that exceeds the file size
59              limit of the process.
60
61       EFBIG  The file is a regular file and an attempt was made to  write  at
62              or  beyond  the offset maximum associated with the corresponding
63              stream.
64
65       EINTR  The fflush() function was interrupted by a signal.
66
67       EIO    The process is a member of a background process group attempting
68              to write to its controlling terminal, TOSTOP is set, the calling
69              thread is not blocking SIGTTOU,  the  process  is  not  ignoring
70              SIGTTOU, and the process group of the process is orphaned.  This
71              error may also be returned under  implementation-defined  condi‐
72              tions.
73
74       ENOMEM The   underlying  stream  was  created  by  open_memstream()  or
75              open_wmemstream() and insufficient memory is available.
76
77       ENOSPC There was no free space remaining on the device  containing  the
78              file or in the buffer used by the fmemopen() function.
79
80       EPIPE  An  attempt  is made to write to a pipe or FIFO that is not open
81              for reading by any process. A SIGPIPE signal shall also be  sent
82              to the thread.
83
84       The fflush() function may fail if:
85
86       ENXIO  A  request  was made of a nonexistent device, or the request was
87              outside the capabilities of the device.
88
89       The following sections are informative.
90

EXAMPLES

92   Sending Prompts to Standard Output
93       The following example uses printf() calls to print a series of  prompts
94       for  information  the user must enter from standard input. The fflush()
95       calls force the output to standard output.  The  fflush()  function  is
96       used because standard output is usually buffered and the prompt may not
97       immediately be printed on the output or terminal. The  getline()  func‐
98       tion  calls  read  strings from standard input and place the results in
99       variables, for use later in the program.
100
101           char *user;
102           char *oldpasswd;
103           char *newpasswd;
104           ssize_t llen;
105           size_t blen;
106           struct termios term;
107           tcflag_t saveflag;
108
109           printf("User name: ");
110           fflush(stdout);
111           blen = 0;
112           llen = getline(&user, &blen, stdin);
113           user[llen-1] = 0;
114           tcgetattr(fileno(stdin), &term);
115           saveflag = term.c_lflag;
116           term.c_lflag &= ~ECHO;
117           tcsetattr(fileno(stdin), TCSANOW, &term);
118           printf("Old password: ");
119           fflush(stdout);
120           blen = 0;
121           llen = getline(&oldpasswd, &blen, stdin);
122           oldpasswd[llen-1] = 0;
123
124           printf("\nNew password: ");
125           fflush(stdout);
126           blen = 0;
127           llen = getline(&newpasswd, &blen, stdin);
128           newpasswd[llen-1] = 0;
129           term.c_lflag = saveflag;
130           tcsetattr(fileno(stdin), TCSANOW, &term);
131           free(user);
132           free(oldpasswd);
133           free(newpasswd);
134

APPLICATION USAGE

136       None.
137

RATIONALE

139       Data buffered by the system may make determining the  validity  of  the
140       position  of  the  current file descriptor impractical. Thus, enforcing
141       the repositioning of the file descriptor after fflush() on streams open
142       for read() is not mandated by POSIX.1‐2008.
143

FUTURE DIRECTIONS

145       None.
146

SEE ALSO

148       Section  2.5,  Standard I/O Streams, fmemopen(), getrlimit(), open_mem‐
149       stream(), ulimit()
150
151       The Base Definitions volume of POSIX.1‐2008, <stdio.h>
152
154       Portions of this text are reprinted and reproduced in  electronic  form
155       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
156       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
157       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
158       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
159       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
160       event of any discrepancy between this version and the original IEEE and
161       The  Open Group Standard, the original IEEE and The Open Group Standard
162       is the referee document. The original Standard can be  obtained  online
163       at http://www.unix.org/online.html .
164
165       Any  typographical  or  formatting  errors that appear in this page are
166       most likely to have been introduced during the conversion of the source
167       files  to  man page format. To report such errors, see https://www.ker
168       nel.org/doc/man-pages/reporting_bugs.html .
169
170
171
172IEEE/The Open Group                  2013                           FFLUSH(3P)
Impressum