Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S_IRUSR semantics in POSIX

Tags:

linux

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 thatR 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...

like image 341
Xinus Avatar asked Jan 26 '10 05:01

Xinus


3 Answers

I am not sure if they have any meaning except that they're in sys/stat.h, so the S may stand for "stat".

I tried doing some detective work, for example, the IEEE Std 1003.1, 2004 Edition entry for sys/stat.h says this: First released in Issue 1. Derived from Issue 1 of the SVID.

Then, the Developer Specs for System V Application Binary Interface (see Volume 1a [pdf]), page 95, and even that has names beginning with S_. I haven't been able to go further back than this.

About your question in general: much of it is history. For example, creat() is in POSIX, but the name comes from history. Many of POSIX function names (and behavior) comes from the C standard. In fact, their description usually have text like:

The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of IEEE Std 1003.1-2001 defers to the ISO C standard.

I think the only way to find any logic behind the POSIX API is to read the history of Unix.

The following may help:

  • Unix history and links there,
  • An oral history of Unix,
  • History and timeline of Unix
like image 198
Alok Singhal Avatar answered Nov 16 '22 17:11

Alok Singhal


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.

like image 25
bta Avatar answered Nov 16 '22 16:11

bta


Alok is correct. See the specification for sys/stat.h. If you were to write your own stat() / statvfs() implementation (very common in ports that make non-posix programs work on POSIX hosts) you would prefix it with something else, i.e. Z_IRUSR.

While I don't have a list handy, I am quite certain that some C implementations provide several choices for sys/stat, S_ giving you typical POSIX behavior and (X) giving you something else. I have not seen that in a long time, though, which is why I can't quite recollect where I ran into it.

like image 41
Tim Post Avatar answered Nov 16 '22 16:11

Tim Post