NAME
fclose - 关闭流
SYNOPSIS 总览
#include <stdio.h>
int fclose(FILE *stream);
DESCRIPTION 描述
函数 fclose 将名为 stream 的流与它底层关联的文件或功能集合断开。如果流曾用作输出,任何缓冲的数据都将首先被写入,使用 fflush(3) 。
RETURN VALUE 返回值
成功执行返回 0,否则返回 EOF 并设置全局变量 errno 来指示错误发生。任何一种情况下,对流再进行存取 (包括再次调用 fclose()) 都会带来未定义的结果。
ERRORS
- EBADF
- stream 底层的文件描述符是无效的。
函数 fclose 也可能失败并置 errno 为 close(2), write(2) 或 fflush(3) 指定的值。
NOTES 要点
注意 fclose 仅仅刷新用户空间的由 C 库提供的缓冲。要保证数据被物理地存储到磁盘上,必须也刷新内核缓冲。例如,使用 sync(2) 或 fsync(2).
CONFORMING TO 标准参考
函数 fclose 遵循 ANSI X3.159-1989 (``ANSI C'') 标准。
SEE ALSO 参见
close(2), fcloseall(3), fflush(3), fopen(3), setbuf(3)
#p#
NAME
fclose - close a stream
SYNOPSIS
#include <stdio.h>
int fclose(FILE *stream);
DESCRIPTION
The fclose function dissociates the named stream from its underlying file or set of functions. If the stream was being used for output, any buffered data is written first, using fflush(3).
RETURN VALUE
Upon successful completion 0 is returned. Otherwise, EOF is returned and the global variable errno is set to indicate the error. In either case any further access (including another call to fclose()) to the stream results in undefined behaviour.
ERRORS
- EBADF
- The filedescriptor underlying stream is not valid.
The fclose function may also fail and set errno for any of the errors specified for the routines close(2), write(2) or fflush(3).
NOTES
Note that fclose only flushes the user space buffers provided by the C library. To ensure that the data is physically stored on disk the kernel buffers must be flushed too, e.g. with sync(2) or fsync(2).
CONFORMING TO
The fclose function conforms to ANSI X3.159-1989 (``ANSI C'').
SEE ALSO
close(2), fcloseall(3), fflush(3), fopen(3), setbuf(3)