[comp.unix.questions] Bit pattern of S_IFREG

martin@mwtech.UUCP (Martin Weitzel) (12/17/89)

In article <2722@auspex.UUCP> guy@auspex.auspex.com (Guy Harris) writes:
[many lines deleted, because not relevant to my question]
>
>	#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 */

I think I have seen on some older systems, that for regular files
you must test for both	(st_mode & S_IFMT) == S_IFREG
and *additionally*	(st_mode & S_IFMT) == 0.

I don't know if this is still true today.
-- 
<<< MW -- email: see header -- voice: 49-(0)6151-6 56 83 >>>

guy@auspex.UUCP (Guy Harris) (12/19/89)

>I think I have seen on some older systems, that for regular files
>you must test for both	(st_mode & S_IFMT) == S_IFREG
>and *additionally*	(st_mode & S_IFMT) == 0.
>
>I don't know if this is still true today.

If it is true on any "V7 derivative" (BSD and S3/S5 count under this
heading), it is due to a colossal screwup on the part of the vendor.  It
may have been true under some emulation of V7 under "last V6", or
something like that.  *I* certainly wouldn't bother testing for
(st_mode & S_IFMT) being 0.

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (12/19/89)

In article <2736@auspex.UUCP> guy@auspex.auspex.com (Guy Harris) writes:
: >I think I have seen on some older systems, that for regular files
: >you must test for both	(st_mode & S_IFMT) == S_IFREG
: >and *additionally*	(st_mode & S_IFMT) == 0.
: >
: >I don't know if this is still true today.
: 
: If it is true on any "V7 derivative" (BSD and S3/S5 count under this
: heading), it is due to a colossal screwup on the part of the vendor.  It
: may have been true under some emulation of V7 under "last V6", or
: something like that.  *I* certainly wouldn't bother testing for
: (st_mode & S_IFMT) being 0.

However, be advised that in BSD (or at least MORE/BSD), fstat() on a socket
returns (st_mode & S_IFMT) == 0.  This one bit me in perl.  Caveat Hackor.

Larry Wall
lwall@jpl-devvax.jpl.nasa.gov