tags:

views:

280

answers:

3

I am learning posix api. I could not get logic behind names used by posix api

e.g. S_IRUSR, S_IRUSR What does What does S stand for? I can get R and W are for read and write. But what naming convention followed by POSIX ?

Its just an example. What about other names ? Just like Win32 follow Hungarian Notation for naming what does POSIX follow for their naming ? For standard like POSIX there must be documentation for it. Can somebody please link it.

thanks for any clue .

+6  A: 

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:

Alok
+1  A: 

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.

Tim Post
You introduced that link as though it was going to back up Alok's answer, but it's the same link Alok gave, and I don't see anything in the specification saying *why* the names all start with S. Also, why would you use different names on non-Posix hosts? Wouldn't that just make the code *less* portable?
Rob Kennedy
@Rob Kennedy: As I noted, (now remember, we're going back to when the single UNIX specification was being hammered out) some systems implemented POSIX on top of their proprietary implementations, so you had to deliberately use POSIX to get POSIX. Hence, namespace was a factor to deal with.You wouldn't use different names on non-posix hosts, you'd use different names ON posix hosts. I accidentally reversed that, thanks!
Tim Post
+3  A: 

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.

bta