Bad file descriptor

后端 未结 3 872
旧时难觅i
旧时难觅i 2021-02-18 16:55

I\'m learning about file descriptors and I wrote this code:

#include 
#include 
#include 
#include          


        
相关标签:
3条回答
  • 2021-02-18 16:55

    According to the open(2) man page:

    The argument flags must include one of the following access modes: O_RDONLY, O_WRONLY, or O_RDWR.

    So yes, as suggested by others, please change your open to open("output", O_CREAT|O_WRONLY, 0777));. Use O_RDWR if you need to read from the file. You may also want O_TRUNC -- see the man page for details.

    0 讨论(0)
  • 2021-02-18 16:56

    I think O_CREAT alone is not enough. Try adding O_WRONLY as flag to the open command.

    0 讨论(0)
  • 2021-02-18 17:14

    Try this:

    open("output", O_CREAT|O_WRONLY, 0777)
    
    0 讨论(0)
提交回复
热议问题