[cs631apue] HW2 Access Mode Question

Jan Schaumann jschauma at stevens.edu
Sat Sep 19 21:53:04 EDT 2015

Yanqiao Zhan <yzhan14 at stevens.edu> wrote:

> I'm dealing with destination file's access mode, but even I explicit mode =
> 777 in *open(const char *path,..., mode_t mode) *function. The new created
> file's access mode still miss write privilege like below.
> -rwxr-xr-x+ 1 yzhan14 student  9881 Sep 19 16:05 b3

As noted, the umask plays a role here.  That is, as explained in the
manual page, the permissions passed to open(2) will be modified by the
current process's umask value.

If you want to assert a specific mode, you have to explicitly unset the
umask prior to calling open(2).

However, considering that the umask is something the user controls, it
is generally the user's intention to have new files created with the
umask applied -- see the princple of least astonishment.  cp(1) has a
flag to tell it to preserve as many attributes as it can ('-p'), but
considering cp(1)'s default behaviour as an example for your simple
tool's behaviour would be a good idea.


More information about the cs631apue mailing list