权限被open()拒绝

时间:2020-05-24 13:43:56

标签: c linux file-io

问题出现在fopen()上,表明权限被拒绝。我尝试输入所有模式,但是这没有成功。添加所有书写模式时相同。我正在尝试打开一个可以写入的文件。感谢提供帮助的人

if(filename != NULL && redirectArrow == true){

    mode_t modes = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
        int fd = open(filename, O_WRONLY | O_CREAT , S_IWUSR | S_IWGRP | S_IWOTH); //opening file in write only, and creating file if it does not exist 

if(fd == -1){
    perror("Failed to create and open the file\n");
    exit(3);
}

0 个答案:

没有答案