The file mode given by stat[2] consists of two distinct pieces of information: the file type and the file permissions. If you want to see only the permissions, you have to mask off the file type portion of the mode. This is what the bitwise and (&) with 07777 does, as shown in my previous post.
The file type corresponds to the first character displayed on a ls -l command under the Unix shell prompt:
$ ls -l /etc/passwd
-rw-r--r-- 1 Laurent root 841 9 mai 23:24 /etc/passwd
The initial dash (-) displayed above says it is a regular file, a
d would indicate a directory, a
l a symbolic link, an
s a socket, etc. This information is the file type displayed in the first half byte (four bits) of the file mode reported by
stat[2].