Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
663 views
in Technique[技术] by (71.8m points)

c - linux mkdir function can't authorize full permission

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...