How to ouput file permissions in unix using c

aDub

Junior Member
Mar 18, 2002
22
0
0
I have a program to write that outputs the file permissions for each file in a directory but I cant figure out how to get the right format for it. It has to ouput it in the format like 755 or 644 or whatever but the st_mode in the stat structure has all those extra information in it but all I need is those last 3 digits. So how do you get rid of all the extra digits?
 

HigherGround

Golden Member
Jan 9, 2000
1,827
0
0
simple, mask off the extra bits ...


struct stat sb;
if(!stat("foo.txt", &sb) == 0)
printf("%o\n", sb.st_mode & 0x1FF);
.
.
.