Subject: Re: CVS commit: src
To: Jason Thorpe <thorpej@nas.nasa.gov>
From: Simon Burge <simonb@telstra.com.au>
List: tech-kern
Date: 09/20/1998 17:58:00
On Sat, 19 Sep 1998 22:21:59 -0700  Jason Thorpe wrote:

> On Sat, 19 Sep 1998 22:42:06 -0700 (PDT) 
>  Simon Burge <simonb@netbsd.org> wrote:
> 
>  > Module Name:	src
>  > Committed By:	simonb
>  > Date:		Sun Sep 20 05:42:06 UTC 1998
>  > 
>  > Modified Files:
>  > 	src/sys/sys: stat.h
>  > Log Message:
>  > Define the S_IS* macros in terms of the S_IF* defines rather than
>  > duplicating magic numbers.
> 
> If you're going to do this, you need to do:
> 
> 	(1) Create _S_IF*.
> 
> 	(2) If !_POSIX_C_SOURCE || _XOPEN_SOURCE, define S_IF* -> _S_IF*
> 
> 	(3) Define S_IS* in t terms of _S_IF*
> 
> This is because S_IF* pollute the namespace.

Dang, just because things recompile under NetBSD doesn't mean it's
right :(

Is something like the following acceptable?  Do any of the _S_IF* need
protecting?  I guess my first foray into standards didn't go too well,
and I didn't even know it!

Simon.
--

#define _S_IFMT   0170000               /* type of file mask */
#define _S_IFIFO  0010000               /* named pipe (fifo) */
#define _S_IFCHR  0020000               /* character special */
#define _S_IFDIR  0040000               /* directory */
#define _S_IFBLK  0060000               /* block special */
#define _S_IFREG  0100000               /* regular */
#define _S_IFLNK  0120000               /* symbolic link */
#define _S_ISVTX  0001000               /* save swapped text even after use */
#define _S_IFSOCK 0140000               /* socket */
#define _S_IFWHT  0160000               /* whiteout */

#if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 
#define S_IFMT   _S_IFMT 
#define S_IFIFO  _S_IFIFO      
#define S_IFCHR  _S_IFCHR  
#define S_IFDIR  _S_IFDIR
#define S_IFBLK  _S_IFBLK      
#define S_IFREG  _S_IFREG  
#define S_IFLNK  _S_IFLNK
#define S_ISVTX  _S_ISVTX      
#endif
#if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 
#define S_IFSOCK _S_IFSOCK  
#define S_IFWHT  _S_IFWHT      
#endif

#define S_ISDIR(m)      ((m & _S_IFMT) == _S_IFDIR)     /* directory */
#define S_ISCHR(m)      ((m & _S_IFMT) == _S_IFCHR)     /* char special */
#define S_ISBLK(m)      ((m & _S_IFMT) == _S_IFBLK)     /* block special */
#define S_ISREG(m)      ((m & _S_IFMT) == _S_IFREG)     /* regular file */
#define S_ISFIFO(m)     ((m & _S_IFMT) == _S_IFIFO)     /* fifo */
#if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
#define S_ISLNK(m)      ((m & _S_IFMT) == _S_IFLNK)     /* symbolic link */
#endif
#if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
#define S_ISSOCK(m)     ((m & _S_IFMT) == _S_IFSOCK)    /* socket */
#define S_ISWHT(m)      ((m & _S_IFMT) == _S_IFWHT)     /* whiteout */
#endif