linux write()


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.

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM