Bit pattern of S_IFREG (was Re: What is wrong with this code ?)

Larry Wall lwall at jpl-devvax.JPL.NASA.GOV
Tue Dec 19 13:55:40 AEST 1989


In article <2736 at auspex.UUCP> guy at 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 at jpl-devvax.jpl.nasa.gov



More information about the Comp.unix.questions mailing list