How to open a file which is in read write execute mode in C (shell programming)

StackOverflow https://stackoverflow.com/questions/19477110

  •  01-07-2022
  •  | 
  •  

質問

I am trying to create a file, but it is opening in locked mode. How to make it in read write execute mode?

switch(choice){
case 1: printf("\n Enter the file: ");
    scanf("%s", file);
    open(file, O_CREAT, S_IRWXG);
    break;
役に立ちましたか?

解決

The third argument of open doesn't actually have to be one of the defined flags. If you want it in +rwe mode for all users, just change your code to

open(file, O_CREAT, 0777);

EDIT: If you'd prefer to use the flags. Just combine them with the | command. You'll end up actually passing the same value in, but many people prefer to use the flags.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top