Create a file in Linux using C

前端 未结 2 1229
小鲜肉
小鲜肉 2021-02-02 11:50

I am trying to create a write only file in C on Linux (Ubuntu). This is my code:

 int fd2 = open (\"/tmp/test.svg\", O_RDWR|O_CREAT);

 if (fd2 != -1) {
   //...         


        
2条回答
  •  不要未来只要你来
    2021-02-02 12:30

    Give access permissions as the third parameter:

    int fd2 = open("/tmp/test.svg", O_RDWR|O_CREAT, 0777);  // Originally 777 (see comments)
    
    if (fd2 != -1) {
        // use file descriptor
        close(fd2);
    }
    

    By doing this, all read, write and execute permissions will be given to user, group and others. Modify the 3rd parameter according to your use.

提交回复
热议问题