linux mkdir function can't authorize full permission

百般思念 提交于 2019-12-18 04:20:30

问题


I am testing the mkdir function to create a new directory:

folder =  mkdir("./linux", 511);

or

 folder = mkdir("./linux", 0777);

or

folder = mkdir("./linux", S_IRWXU | S_IRWXG | S_IRWXO);

As you can see, I try to authorize the full permission to the directory but here's what comes up with ls -l | grep linux:

drwxr-xr-x 2 manuzhang manuzhang 4096 2012-01-04 06:53 linux

why can't I authorize write permission for group and others?

Updates:
weird thing, as you guys told me I tried umask. It works with either umask(S_IWGRP) or umask(S_IWOTH) but fails with umask(S_IWGRP | S_IWOTH), any ideas?


回答1:


From man 2 mkdir:

The argument mode specifies the permissions to use. It is modified by the process's umask in the usual way: the permissions of the created directory are (mode & ~umask & 0777).

I suggest you look at your umask - it is probably set to 0022. Try a chmod post-mkdir.




回答2:


Permissions set by system calls like mkdir and open are always masked against the current process's umask. You can change the current umask using the umask() function; make sure to set it back when you're done.




回答3:


Check the umask function: man 2 umask



来源:https://stackoverflow.com/questions/8719867/linux-mkdir-function-cant-authorize-full-permission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!