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