sandrei
sandrei

Reputation: 3

The execution of open when using O_CREAT

I'm trying to understand some of the basics of os and I got stuck between flags and permissions.

If open() is used the follofing way int fd = open(path, O_CREAT | O_RDWR, 0000); in which conditions our file will have 0000 permissions and in which conditions our file will have 0666 conditions ?

At first I thought that if the file is already created, we will use it with 0000 permissions and if it's not created, will be created and used with 0666 permissions. I'm not really sure if i'm correct.

Upvotes: 0

Views: 1745

Answers (1)

Neeraj Bansal
Neeraj Bansal

Reputation: 390

  • If this open command is creating a new file then only mode=0000 is applicable here.
  • If the file already exists then it doesn't matter what the value of mode is.

Here you are using mode=0000. If the file doesn't exist then it will assign "0000" permissions which means no one (user, group, other) has any read|write|execute permission. Please use the proper mode value.

Upvotes: 2

Related Questions