home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / volume.19 / text0015.txt < prev    next >
Encoding:
Internet Message Format  |  1990-05-17  |  2.2 KB

  1. From: Doug Gwyn <uunet!smoke.brl.mil!gwyn>
  2.  
  3. In article <580@longway.TIC.COM> std-unix@uunet.uu.net writes:
  4. >From: andrew@alice.uucp (Andrew Hume)
  5. >the posix 1003.1 standard has cleverly evaded naming of bits
  6. >in the mode field of the stat structure. it does this by
  7. >defining tests (like S_ISDIR(mode) rather than (mode&S_IFMT)==S_IFDIR).
  8. >the question is, how do people deal with sym links? I simply
  9. >added a S_ISLNK macro but would prefer to go with the flow
  10. >if there is one.
  11.  
  12. I think that would be the most obvious name for such a macro.
  13. Unfortunately, so far as I can tell IEEE Std 1003.1-1988 fails
  14. to stake out portions of macro name space for headers such as
  15. <fcntl.h> (O_*) and <sys/stat.h> (S_*).  (I had thought that it
  16. had, but I can't seem to find such provisions now; 2.8.2's
  17. definition of the action of _POSIX_SOURCE was supposed to
  18. support this.)
  19.  
  20. >From the point of view of 1003.1, S_ISLNK() is not very useful,
  21. because both stat() and fstat() treat symbolic links as
  22. "transparent", and 1003.1 doesn't mention lstat() which is the
  23. function for which S_ISLNK() has a real use.
  24.  
  25. Probably the best solution for implementors is along these lines:
  26.  
  27.     /* <sys/stat.h> */
  28.     ...
  29.     #define    _S_IFMT        0170000    /* type of file: */
  30.     #define    _S_IFDIR    0040000    /* directory */
  31.     #define    _S_IFCHR    0020000    /* character special */
  32.     #define    _S_IFBLK    0060000    /* block special */
  33.     #define    _S_IFREG    0100000    /* regular */
  34.     #define    _S_IFLNK    0120000    /* symbolic link */
  35.     #define    _S_IFSOCK    0140000 /* socket */
  36.     #define    _S_IFIFO    0010000    /* fifo */
  37.  
  38.     #define    S_ISBLK(mode)    (((mode) & _S_IFMT) == _S_IFBLK)
  39.     #define    S_ISCHR(mode)    (((mode) & _S_IFMT) == _S_IFCHR)
  40.     #define    S_ISDIR(mode)    (((mode) & _S_IFMT) == _S_IFDIR)
  41.     #define    S_ISFIFO(mode)    (((mode) & _S_IFMT) == _S_IFIFO)
  42.     #define    S_ISREG(mode)    (((mode) & _S_IFMT) == _S_IFREG)
  43.  
  44.     #ifndef _POSIX_SOURCE    /* enable "common usage" extensions */
  45.  
  46.     #define    S_ISLNK(mode)    (((mode) & _S_IFMT) == _S_IFLNK)
  47.     #define    S_ISSOCK(mode)    (((mode) & _S_IFMT) == _S_IFSOCK)
  48.  
  49.     #define    S_IFMT        _S_IFMT
  50.     #define    S_IFDIR        _S_IFDIR
  51.     #define    S_IFCHR        _S_IFCHR
  52.     #define    S_IFBLK        _S_IFBLK
  53.     #define    S_IFREG        _S_IFREG
  54.     #define    S_IFLNK        _S_IFLNK
  55.     #define    S_IFSOCK    _S_IFSOCK
  56.     #define    S_IFIFO        _S_IFIFO
  57.  
  58.     #endif    /* !_POSIX_SOURCE */
  59.     ...
  60.  
  61. Volume-Number: Volume 19, Number 18
  62.  
  63.