Linux write():ssize_t write (int fd, const void * buf, size_t count)

有可能返回成功值,但实际并未成功写入的情况

因此,使用write()返回值作为文件写成功与否不完全正确,还需判断一下errno

 

open()

open("in.txt", O_RDONLY);  // 阻塞模式

open("in.txt", O_RDONLY|O_NONBLOCK);  // 非阻塞模式

O_NONBLOCK

When opening a FIFO with O_RDONLY or O_WRONLY set:

* If O_NONBLOCK is set, an open() for reading-only shall return without delay. An open() for writing-only shall return an error if no
process currently has the file open for reading.

* If O_NONBLOCK is clear, an open() for reading-only shall block the calling thread until a thread opens the file for writing. An open()
for writing-only shall block the calling thread until a thread opens the file for reading.

 

相关文章:

  • 2022-01-07
  • 2022-02-20
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2021-04-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-04
  • 2022-02-15
  • 2021-12-18
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案