Why are the file permissions changed when creating a file with the open system call on Linux?

后端 未结 3 1520
-上瘾入骨i
-上瘾入骨i 2020-12-11 14:34

I am creating a file with full permission (777) using the open system call, but when I do ls -l I can see only permission as (755). Could you pleas

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 14:44

    The permissions of a created file are restricted by the process's current umask -- your current umask is 022, so group and world write are always disabled by default. (Which is a good thing, in most cases.) If you really want a group- and world-writable file, you will need to temporarily set umask(0) while creating this file (make sure to save the old value returned by the system call, and set it back afterwards!), or "manually" set the file's permissions using chmod().

提交回复
热议问题