I am a beginner to Unix programming and C and I have two questions regarding the stat struc
and its field st_mode
:
When accessing the
st_mode
field as below, what type of number is returned ( octal, decimal, etc.)?struct stat file; stat( someFilePath, &file); printf("%d", file.st_mode );
I thought the number is in octal but when I ran this code, and I got the value 33188
. What is the base?
- I found out that the
st_mode
encodes a 16 bit binary number that represents the file type and file permissions. How do I get the 16-bit number from the above output (especially when it doesn't seem to be in octal). And which parts of the 16-bit digit encode which information?
Thanks for any help.
printf("%o", file.st_mode );
should get you the (hopefully) familiar octal form of the mode.