consider this line of code:
file_desc = open(file, O_RDWR | O_CREAT | O_EXCL, 0444);
how can you open 'file' with read only permissions for owner/group/other (the 0444) while you say open it with O_RDWR access mode? thanx
From the open man page:
Note that this mode only applies to future accesses of the newly created file; the open() call that creates a read-only file may well return a read/write file descriptor.
So the process that creates the file can write to it, but some other process can't (unless it changes the permissions first). This ensures that the creating process can fill in the fill without worrying about some other process inadvertently overwriting it. Without this feature, it would have to create the process with write permission, fill it in, then remove the write permission, which would allow a window during which some other process could overwrite it.