#define COPYMODE 0644
creat(argV[2],COPYMODE);I have these two lines of code in a copy.c file. I don't know what it means. Please give some example about it
22 Answers
There are 3x3 bit flags for a mode:
- (owning) User
- read
- write
- execute
- Group
- read
- write
- execute
- Other
- read
- write
- execute
So each triple encodes nicely as an octal digit.
rwx oct meaning
--- --- -------
001 01 = execute
010 02 = write
011 03 = write & execute
100 04 = read
101 05 = read & execute
110 06 = read & write
111 07 = read & write & executeSo 0644 is:
* (owning) User: read & write
* Group: read
* Other: readNote that in C, an initial 0 indicates octal notation, just like 0x indicates hexadecimal notation. So every time you write plain zero in C, it's actually an octal zero (fun fact).
This might also be written:
-rw-r--r--Whereas full permissions, 0777 can also be written:
-rwxrwxrwxSo the octal number passed to creat corresponds directly (via octal encoding of the bit-pattern) to the file permissions as displayed by ls -l.
It means that:
- The file's owner can read and write (6)
- Users in the same group as the file's owner can read (first 4)
- All users can read (second 4)
See .
1