home *** CD-ROM | disk | FTP | other *** search
- From: Doug Gwyn <uunet!smoke.brl.mil!gwyn>
-
- In article <580@longway.TIC.COM> std-unix@uunet.uu.net writes:
- >From: andrew@alice.uucp (Andrew Hume)
- >the posix 1003.1 standard has cleverly evaded naming of bits
- >in the mode field of the stat structure. it does this by
- >defining tests (like S_ISDIR(mode) rather than (mode&S_IFMT)==S_IFDIR).
- >the question is, how do people deal with sym links? I simply
- >added a S_ISLNK macro but would prefer to go with the flow
- >if there is one.
-
- I think that would be the most obvious name for such a macro.
- Unfortunately, so far as I can tell IEEE Std 1003.1-1988 fails
- to stake out portions of macro name space for headers such as
- <fcntl.h> (O_*) and <sys/stat.h> (S_*). (I had thought that it
- had, but I can't seem to find such provisions now; 2.8.2's
- definition of the action of _POSIX_SOURCE was supposed to
- support this.)
-
- >From the point of view of 1003.1, S_ISLNK() is not very useful,
- because both stat() and fstat() treat symbolic links as
- "transparent", and 1003.1 doesn't mention lstat() which is the
- function for which S_ISLNK() has a real use.
-
- Probably the best solution for implementors is along these lines:
-
- /* <sys/stat.h> */
- ...
- #define _S_IFMT 0170000 /* type of file: */
- #define _S_IFDIR 0040000 /* directory */
- #define _S_IFCHR 0020000 /* character special */
- #define _S_IFBLK 0060000 /* block special */
- #define _S_IFREG 0100000 /* regular */
- #define _S_IFLNK 0120000 /* symbolic link */
- #define _S_IFSOCK 0140000 /* socket */
- #define _S_IFIFO 0010000 /* fifo */
-
- #define S_ISBLK(mode) (((mode) & _S_IFMT) == _S_IFBLK)
- #define S_ISCHR(mode) (((mode) & _S_IFMT) == _S_IFCHR)
- #define S_ISDIR(mode) (((mode) & _S_IFMT) == _S_IFDIR)
- #define S_ISFIFO(mode) (((mode) & _S_IFMT) == _S_IFIFO)
- #define S_ISREG(mode) (((mode) & _S_IFMT) == _S_IFREG)
-
- #ifndef _POSIX_SOURCE /* enable "common usage" extensions */
-
- #define S_ISLNK(mode) (((mode) & _S_IFMT) == _S_IFLNK)
- #define S_ISSOCK(mode) (((mode) & _S_IFMT) == _S_IFSOCK)
-
- #define S_IFMT _S_IFMT
- #define S_IFDIR _S_IFDIR
- #define S_IFCHR _S_IFCHR
- #define S_IFBLK _S_IFBLK
- #define S_IFREG _S_IFREG
- #define S_IFLNK _S_IFLNK
- #define S_IFSOCK _S_IFSOCK
- #define S_IFIFO _S_IFIFO
-
- #endif /* !_POSIX_SOURCE */
- ...
-
- Volume-Number: Volume 19, Number 18
-
-