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