What is wrong with this code ?

Clarence Dold dold at mitisft.Convergent.COM
Mon Dec 11 16:05:35 AEST 1989


in article <1156 at nsscb.UUCP>, nrg at nsscb.UUCP (G.Narotham Reddy) says:

Oh, so judgemental!  Who says it's stupid precedence?
True, we do need a couple of parens to make it work, "it" being this 
one line, but don't we also need some logic in the program?

> if (nfile.st_mode & S_IFMT == S_IFREG) 
> else if (nfile.st_mode & S_IFMT == S_IEXEC) 

all these "else if" are self-defeating.  Might argv[1] not point to a file 
that satisfies more than one?  How will any of them ever display, if we
else if the permissions against S_IFREG to begin with?  (only for a special).
Additionally, we don't want to mask permissions against S_IFMT.
For that matter, we don't need to mask type against S_IFMT.

Don't we really want
if (nfile.st_mode & S_IFREG) 
	printf(...);
else if (nfile.st_mode & S_IFDIR)
	printf(...);

followed by several
if (nfile.st_mode & S_IWRITE) 
	printf(...);
if (nfile.st_mode & S_IREAD) 
	printf(...);
...
-- 
---
Clarence A Dold - dold at tsmiti.Convergent.COM            (408) 435-5293
               ...pyramid!ctnews!tsmiti!dold        FAX (408) 435-3105
               P.O.Box 6685, San Jose, CA 95150-6685         MS#10-007



More information about the Comp.lang.c mailing list