C. Buffer
C. Buffer

Reputation: 11

How does the third parameter in open() system call work?

int fd = open("float.txt", O_CREAT | O_WRONLY, 0600);

I know the 0600 has to do with permissions, but how exactly does it work?

Upvotes: 0

Views: 3675

Answers (1)

selbie
selbie

Reputation: 104474

You need to use the 3 param version of open when using the O_CREAT flag:

As per the man page for open:

int open(const char *pathname, int flags);

int open(const char *pathname, int flags, mode_t mode);

The mode argument specifies the file mode bits be applied when a new file is created. This argument must be supplied when O_CREAT or O_TMPFILE is specified in flags; if neither O_CREAT nor O_TMPFILE is specified, then mode is ignored.

Try this instead:

int fd = open("float.txt", O_CREAT | O_WRONLY, S_IRUSR|S_IWUSR);

Upvotes: 3

Related Questions