From: ghazi@caip.rutgers.edu (Kaveh R. Ghazi)
Subject: Re: Autoconf (GNU configure script generator) available
Organization: GNUs Not Usenet
Distribution: gnu
Date: Mon, 20 Jul 1992 22:45:14 GMT

Hi,

	I posted a patch for gnufind 3 weeks back and now it seems it is more
applicable to autoconf.  There are at least three (maybe more) systems where
this is useful.  It regards macros in <sys/stat.h> which mistakenly assume
the following is correct:
#define S_ISBLK(m)      (m & S_IFBLK)   /* True if block special file */

This macro really should be defined as:
#define S_ISBLK(m)      (((m)&_IFMT) == _IFBLK)

The first case mistakenly causes cross matches between BLK and DIR types.


	I've devised a simple way to detect and remedy this problem and it
could easily fit in with autoconf.  Please consider incorporating it into the
next release.
	I've included the text of my posting for gnufind which explains
things in more detail.
		Thanks,
		--Kaveh



 >From ghazi@michelangelo.rutgers.edu (Kaveh R. Ghazi) Wed Jul  1 18:07:49 1992
 >Path: dziuxsolim.rutgers.edu!rutgers!att!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!michelangelo.rutgers.edu!ghazi
 >From: ghazi@michelangelo.rutgers.edu (Kaveh R. Ghazi)
 >Newsgroups: gnu.utils.bug
 >Subject: gnufind 3.6 patches (2nd patch applies to many GNU packages)
 >Message-ID: <Jul.1.18.07.49.1992.2454@michelangelo.rutgers.edu>
 >Date: 1 Jul 92 22:07:49 GMT
 >Sender: gnulists@ai.mit.edu
 >Distribution: gnu
 >Organization: Rutgers Univ., New Brunswick, N.J.
 >Lines: 70
 >Approved: bug-gnu-utils@prep.ai.mit.edu
 >
 >
 >	I ported gnu find v3.6 to a Tek XD88/10 and a Motorola MPC.  They both
 >required the following two fixes.
 >
 >1.	updatedb needs a fix because the fstype for network file systems
 >is "NFS" not "nfs' on these machines.  Here's the diff:
 >
 >57c57
 ><   \( -fstype nfs -o -type d -regex "$PRUNEREGEX" \) -prune -o -print
 >---
 >>   \( -fstype nfs -o -fstype NFS -o -type d -regex "$PRUNEREGEX" \) -prune -o -print
 >
 >
 >
 >2.	I also had to add a fix to correct bad definitions of S_ISBLK, etc.
 >
 >They are defined like this:
 >#define S_ISBLK(m)      (m & S_IFBLK)   /* True if block special file */
 >
 >They should be of this form:
 >#define S_ISBLK(m)      (((m)&_IFMT) == _IFBLK)
 >
 >	While the broken macros work in a lot of cases, an example of a failure
 >is that S_ISBLK on a directory returns true.
 >	I basically copied the fix for this problem from perl and put it in
 >by hand, but it really should be added to the configure script for find and
 >actually all gnu utilities which use those macros (shellutils, fileutils
 >and textutils come to mind.)  This change also fixes this problem for uts
 >machines according to the source code #ifdefs in perl.  I bet other machines
 >have silently had this bug for a while also.
 >
 >	I wrote a small C program to test for the problem:
 >
 >#include <sys/types.h>
 >#include <sys/stat.h>
 >main()
 >{
 >        struct stat foo;
 >
 >        stat(".",&foo);
 >        if (S_ISBLK(foo.st_mode))  exit(1)
 >	exit(0);
 >}
 >
 >	If configure gets an exit(1) from this program then it should add a
 >define to the make process which invokes the code below wherever the source
 >code wants to include <sys/stat.h>:
 >
 >#include <sys/stat.h>
 >#if defined(BROKEN_S_IS_MACROS)
 >#undef S_ISDIR
 >#undef S_ISCHR
 >#undef S_ISBLK
 >#undef S_ISREG
 >#undef S_ISFIFO
 >#undef S_ISLNK
 >#define S_ISDIR(P) (((P)&S_IFMT)==S_IFDIR)
 >#define S_ISCHR(P) (((P)&S_IFMT)==S_IFCHR)
 >#define S_ISBLK(P) (((P)&S_IFMT)==S_IFBLK)
 >#define S_ISREG(P) (((P)&S_IFMT)==S_IFREG)
 >#define S_ISFIFO(P) (((P)&S_IFMT)==S_IFIFO)
 >#ifdef S_IFLNK
 >#define S_ISLNK(P) (((P)&S_IFMT)==S_IFLNK)
 >#endif
 >#endif
 >
 >		--Kaveh
-- 
Kaveh R. Ghazi			CAIP Center, Rutgers University.
ghazi@caip.rutgers.edu		rutgers!caip.rutgers.edu!ghazi

Newsgroups: gnu.utils.bug