fclose_fclose –关闭流

fclose

fclose is a frequently used C standard library which closes the file associated with the stream and disassociates it.

fclose是一个常用的C标准库,它关闭与关联的文件并取消关联。

名称 (NAME)

fclose – close a stream

fclose –关闭流

概要 (SYNOPSIS)

#include <stdio.h>
int fclose(FILE *fp);

描述 (DESCRIPTION)

The fclose() function will flushes the stream pointed to by fp (writing any buffered output data using fflush()) and closes the underlying file descriptor.

fclose()函数将刷新fp指向的流(使用fflush()写入任何缓冲的输出数据)并关闭基础文件描述符。

返回值 (RETURN VALUE)

Upon successful completion 0 is returned.  Otherwise, EOF is returned and 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.

成功完成后,将返回0。 否则,将返回EOF并将errno设置为指示错误 。 在任何一种情况下,对该流的任何进一步访问(包括对fclose()的另一个调用)都会导致未定义的行为。

错误 (ERRORS)

EBADF  The file descriptor underlying fp is not valid.

EBADF fp底层的文件描述符无效。

The fclose() function may also fail and set errno for any of the errors  specified  for  the  routines  close(),
write() or fflush().

fclose()函数也可能会失败,并为例程close()指定的任何错误设置errno,
write()或fflush()。

符合 (CONFORMING TO)

C89, C99.

C89,C99。

笔记 (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, for example, with sync() or fsync().

请注意,fclose()仅刷新C库提供的用户空间缓冲区。 为了确保将数据物理存储在磁盘上,内核缓冲区也必须进行刷新,例如,使用sync()或fsync()。

From Linux Programmer’s Manual

摘自Linux程序员手册

(EXAMPLE)

#include <stdio.h>
int main(int argc, char* args[])
{
  FILE * fp;
  pFile = fopen ("file_to_write.txt","wt");
  fprintf (fp, "fclose example");
  fclose (fp);
  return 0;
}

翻译自: https://www.systutorials.com/fclose-close-a-stream/

fclose

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值