Xinus Xinus - 26 days ago 22
Linux Question

S_IRUSR semantics in POSIX

I am learning the POSIX API, and I don't understand the logic behind some of the names.

e.g.

S_IRUSR
,
S_IRUSR


What does What does the
S
stand for? I get that
R
and
W
are for read and write. But what naming convention followed by POSIX? Just like Win32 follows Hungarian Notation for naming, what does POSIX follow for their naming? For standards like POSIX, there must be documentation for it...

bta bta
Answer

The leading S_ is just to identify what structure/function the constant goes with.

From <sys/stat.h>, the constants S_IRUSR, S_IWUSR, etc are possible values for the st_mode member for struct stat (used in stat() and friends). All the members of struct stat start with the prefix st_, and there are several stat-related macros that also start with S_. The convention is merely there to make matching structure names, member names, and constants easier.

Comments