1FFLUSH(P) POSIX Programmer's Manual FFLUSH(P)
2
3
4
6 fflush - flush a stream
7
9 #include <stdio.h>
10
11 int fflush(FILE *stream);
12
13
15 If stream points to an output stream or an update stream in which the
16 most recent operation was not input, fflush() shall cause any unwritten
17 data for that stream to be written to the file, and the st_ctime and
18 st_mtime fields of the underlying file shall be marked for update.
19
20 If stream is a null pointer, fflush() shall perform this flushing
21 action on all streams for which the behavior is defined above.
22
24 Upon successful completion, fflush() shall return 0; otherwise, it
25 shall set the error indicator for the stream, return EOF, and set
26 errno to indicate the error.
27
29 The fflush() function shall fail if:
30
31 EAGAIN The O_NONBLOCK flag is set for the file descriptor underlying
32 stream and the process would be delayed in the write operation.
33
34 EBADF The file descriptor underlying stream is not valid.
35
36 EFBIG An attempt was made to write a file that exceeds the maximum
37 file size.
38
39 EFBIG An attempt was made to write a file that exceeds the process'
40 file size limit.
41
42 EFBIG The file is a regular file and an attempt was made to write at
43 or beyond the offset maximum associated with the corresponding
44 stream.
45
46 EINTR The fflush() function was interrupted by a signal.
47
48 EIO The process is a member of a background process group attempting
49 to write to its controlling terminal, TOSTOP is set, the process
50 is neither ignoring nor blocking SIGTTOU, and the process group
51 of the process is orphaned. This error may also be returned
52 under implementation-defined conditions.
53
54 ENOSPC There was no free space remaining on the device containing the
55 file.
56
57 EPIPE An attempt is made to write to a pipe or FIFO that is not open
58 for reading by any process. A SIGPIPE signal shall also be sent
59 to the thread.
60
61
62 The fflush() function may fail if:
63
64 ENXIO A request was made of a nonexistent device, or the request was
65 outside the capabilities of the device.
66
67
68 The following sections are informative.
69
71 Sending Prompts to Standard Output
72 The following example uses printf() calls to print a series of prompts
73 for information the user must enter from standard input. The fflush()
74 calls force the output to standard output. The fflush() function is
75 used because standard output is usually buffered and the prompt may not
76 immediately be printed on the output or terminal. The gets() calls read
77 strings from standard input and place the results in variables, for use
78 later in the program.
79
80
81 #include <stdio.h>
82 ...
83 char user[100];
84 char oldpasswd[100];
85 char newpasswd[100];
86 ...
87 printf("User name: ");
88 fflush(stdout);
89 gets(user);
90
91
92 printf("Old password: ");
93 fflush(stdout);
94 gets(oldpasswd);
95
96
97 printf("New password: ");
98 fflush(stdout);
99 gets(newpasswd);
100 ...
101
103 None.
104
106 Data buffered by the system may make determining the validity of the
107 position of the current file descriptor impractical. Thus, enforcing
108 the repositioning of the file descriptor after fflush() on streams open
109 for read() is not mandated by IEEE Std 1003.1-2001.
110
112 None.
113
115 getrlimit() , ulimit() , the Base Definitions volume of
116 IEEE Std 1003.1-2001, <stdio.h>
117
119 Portions of this text are reprinted and reproduced in electronic form
120 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
121 -- Portable Operating System Interface (POSIX), The Open Group Base
122 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
123 Electrical and Electronics Engineers, Inc and The Open Group. In the
124 event of any discrepancy between this version and the original IEEE and
125 The Open Group Standard, the original IEEE and The Open Group Standard
126 is the referee document. The original Standard can be obtained online
127 at http://www.opengroup.org/unix/online.html .
128
129
130
131IEEE/The Open Group 2003 FFLUSH(P)