Click to See Complete Forum and Search --> : help with mkdir


bsamuels
10-08-2003, 11:11 PM
Could someone send an example of using the system call mkdir to create a new directory with all permissions on. I'm not clear on the use of the mode parameter.
Thanks, you have been a great help on getting me started.

clw54
10-08-2003, 11:52 PM
mkdir -m 777 directoryname

stoe
10-09-2003, 12:41 AM
are you asking in the context of a shell script or in the context of a c program (or in context of an assembly language program?):

if your referring mkdir as defined in libc, check out this page:
http://www.gnu.org/manual/glibc-2.2.5/html_node/Permission-Bits.html#Permission%20Bits
it lists the permissions as symbollic constants, so you can simply bitwise OR together the set of permissions you want, ie:


int res = mkdir("/some/dir", S_IRWXU | S_IRWXG | S_IRWXO);


If you are specifying the integer constant yourself, perhaps your confusion is over the fact it must be specified in octal?


int res = mkdir("/some/dir", 0777);


note the leading zero on the constant above. in C that's how
you indicate an integer constant is specified in octal.