logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

fflush.3p (6212B)


  1. '\" et
  2. .TH FFLUSH "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. fflush
  12. \(em flush a stream
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <stdio.h>
  17. .P
  18. int fflush(FILE *\fIstream\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The functionality described on this reference page is aligned with the
  22. ISO\ C standard. Any conflict between the requirements described here and the
  23. ISO\ C standard is unintentional. This volume of POSIX.1\(hy2017 defers to the ISO\ C standard.
  24. .P
  25. If
  26. .IR stream
  27. points to an output stream or an update stream in which the most recent
  28. operation was not input,
  29. \fIfflush\fR()
  30. shall cause any unwritten data for that stream to be written to the
  31. file,
  32. and the last data modification and last file status change timestamps
  33. of the underlying file shall be marked for update.
  34. .P
  35. For a stream open for reading with an underlying file description,
  36. if the file is not already at EOF, and the file is one capable
  37. of seeking, the file offset of the underlying open file description
  38. shall be set to the file position of the stream, and any characters
  39. pushed back onto the stream by
  40. \fIungetc\fR()
  41. or
  42. \fIungetwc\fR()
  43. that have not subsequently been read from the stream shall be discarded
  44. (without further changing the file offset).
  45. .P
  46. If
  47. .IR stream
  48. is a null pointer,
  49. \fIfflush\fR()
  50. shall perform this flushing action on all streams for which the
  51. behavior is defined above.
  52. .SH "RETURN VALUE"
  53. Upon successful completion,
  54. \fIfflush\fR()
  55. shall return 0; otherwise, it shall set the error indicator for
  56. the stream, return EOF,
  57. and set
  58. .IR errno
  59. to indicate the error.
  60. .SH ERRORS
  61. The
  62. \fIfflush\fR()
  63. function shall fail if:
  64. .TP
  65. .BR EAGAIN
  66. The O_NONBLOCK flag is set for the file descriptor underlying
  67. .IR stream
  68. and the thread would be delayed in the write operation.
  69. .TP
  70. .BR EBADF
  71. The file descriptor underlying
  72. .IR stream
  73. is not valid.
  74. .TP
  75. .BR EFBIG
  76. An attempt was made to write a file that exceeds the maximum file size.
  77. .TP
  78. .BR EFBIG
  79. An attempt was made to write a file that exceeds the file size
  80. limit of the process.
  81. .TP
  82. .BR EFBIG
  83. The file is a regular file and an attempt was made to write at or
  84. beyond the offset maximum associated with the corresponding stream.
  85. .TP
  86. .BR EINTR
  87. The
  88. \fIfflush\fR()
  89. function was interrupted by a signal.
  90. .TP
  91. .BR EIO
  92. The process is a member of a background process group attempting to
  93. write to its controlling terminal, TOSTOP is set, the calling thread
  94. is not blocking SIGTTOU, the process is not ignoring SIGTTOU, and the
  95. process group of the process is orphaned.
  96. This error may also be returned under implementation-defined conditions.
  97. .TP
  98. .BR ENOMEM
  99. The underlying stream was created by
  100. \fIopen_memstream\fR()
  101. or
  102. \fIopen_wmemstream\fR()
  103. and insufficient memory is available.
  104. .TP
  105. .BR ENOSPC
  106. There was no free space remaining on the device containing the file or
  107. in the buffer used by the
  108. \fIfmemopen\fR()
  109. function.
  110. .TP
  111. .BR EPIPE
  112. An attempt is made to write to a pipe or FIFO that is not open for
  113. reading by any process. A SIGPIPE signal shall also be sent to the thread.
  114. .P
  115. The
  116. \fIfflush\fR()
  117. function may fail if:
  118. .TP
  119. .BR ENXIO
  120. A request was made of a nonexistent device, or the request was
  121. outside the capabilities of the device.
  122. .LP
  123. .IR "The following sections are informative."
  124. .SH EXAMPLES
  125. .SS "Sending Prompts to Standard Output"
  126. .P
  127. The following example uses
  128. \fIprintf\fR()
  129. calls to print a series of prompts for information the user must enter
  130. from standard input. The
  131. \fIfflush\fR()
  132. calls force the output to standard output. The
  133. \fIfflush\fR()
  134. function is used because standard output is usually buffered and the
  135. prompt may not immediately be printed on the output or terminal. The
  136. \fIgetline\fR()
  137. function calls read strings from standard input and place the
  138. results in variables, for use later in the program.
  139. .sp
  140. .RS 4
  141. .nf
  142. char *user;
  143. char *oldpasswd;
  144. char *newpasswd;
  145. ssize_t llen;
  146. size_t blen;
  147. struct termios term;
  148. tcflag_t saveflag;
  149. .P
  150. printf("User name: ");
  151. fflush(stdout);
  152. blen = 0;
  153. llen = getline(&user, &blen, stdin);
  154. user[llen-1] = 0;
  155. tcgetattr(fileno(stdin), &term);
  156. saveflag = term.c_lflag;
  157. term.c_lflag &= \(tiECHO;
  158. tcsetattr(fileno(stdin), TCSANOW, &term);
  159. printf("Old password: ");
  160. fflush(stdout);
  161. blen = 0;
  162. llen = getline(&oldpasswd, &blen, stdin);
  163. oldpasswd[llen-1] = 0;
  164. .P
  165. printf("\enNew password: ");
  166. fflush(stdout);
  167. blen = 0;
  168. llen = getline(&newpasswd, &blen, stdin);
  169. newpasswd[llen-1] = 0;
  170. term.c_lflag = saveflag;
  171. tcsetattr(fileno(stdin), TCSANOW, &term);
  172. free(user);
  173. free(oldpasswd);
  174. free(newpasswd);
  175. .fi
  176. .P
  177. .RE
  178. .SH "APPLICATION USAGE"
  179. None.
  180. .SH RATIONALE
  181. Data buffered by the system may make determining the validity of the
  182. position of the current file descriptor impractical. Thus, enforcing
  183. the repositioning of the file descriptor after
  184. \fIfflush\fR()
  185. on streams open for
  186. \fIread\fR()
  187. is not mandated by POSIX.1\(hy2008.
  188. .SH "FUTURE DIRECTIONS"
  189. None.
  190. .SH "SEE ALSO"
  191. .IR "Section 2.5" ", " "Standard I/O Streams",
  192. .IR "\fIfmemopen\fR\^(\|)",
  193. .IR "\fIgetrlimit\fR\^(\|)",
  194. .IR "\fIopen_memstream\fR\^(\|)",
  195. .IR "\fIulimit\fR\^(\|)"
  196. .P
  197. The Base Definitions volume of POSIX.1\(hy2017,
  198. .IR "\fB<stdio.h>\fP"
  199. .\"
  200. .SH COPYRIGHT
  201. Portions of this text are reprinted and reproduced in electronic form
  202. from IEEE Std 1003.1-2017, Standard for Information Technology
  203. -- Portable Operating System Interface (POSIX), The Open Group Base
  204. Specifications Issue 7, 2018 Edition,
  205. Copyright (C) 2018 by the Institute of
  206. Electrical and Electronics Engineers, Inc and The Open Group.
  207. In the event of any discrepancy between this version and the original IEEE and
  208. The Open Group Standard, the original IEEE and The Open Group Standard
  209. is the referee document. The original Standard can be obtained online at
  210. http://www.opengroup.org/unix/online.html .
  211. .PP
  212. Any typographical or formatting errors that appear
  213. in this page are most likely
  214. to have been introduced during the conversion of the source files to
  215. man page format. To report such errors, see
  216. https://www.kernel.org/doc/man-pages/reporting_bugs.html .