My favorites | Sign in
Project Logo
                
New issue | Search
for
| Advanced search | Search tips
Issue 9: should use S_ISLNK and S_ISDIR
2 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Jul 2008
Type-Defect
Priority-Medium


Sign in to add a comment
 
Reported by e...@jessies.org, Jun 24, 2008
it's not necessarily correct to test (mode & S_IFLNK) == S_IFLNK or (mode &
S_IFDIR) == S_IFDIR; you want to test all the S_IFMT bits. easiest to use
the provided S_ISLNK and S_ISDIR macros...


distcc.diff.txt
822 bytes Download
Comment 1 by zhanglei, Jun 30, 2008
Why is it not correct? If you expand out the S_ISDIR macro, it basically does the
same thing.
Comment 2 by e...@jessies.org, Jun 30, 2008
no; expand out the S_ISDIR macro, and you'll see the difference between the broken
code in distcc and the S_ISDIR macro is exactly what i said above: you need to use (m
& S_IFMT).

taking the example of S_IFDIR...

good code: ((m & S_IFMT) == S_IFDIR)
distcc:    ((m & S_IFDIR) == S_IFDIR)

if you're saying you don't understand why they're not equivalent, try substituting in
S_IFSOCK for m.

but, like i said, best of all is to use S_ISLNK and S_ISDIR because someone else
worries about whether they're correct, and they're more intention-revealing anyway.
Comment 3 by zhanglei, Jul 01, 2008
Ok, the results will be different, but only if stat() reports the file is both a
directory and a {fifo, char device, etc...}. The chances of that happening are very
rare, and if that ever happens, you probably have more serious problems to worry about.

I agree using the macros makes the code more readable. Please send the patch to:
distcc-patches at googlegroups.com. I don't know if patches get picked up from here.
See: http://lists.samba.org/archive/distcc/2008q2/003670.html
Comment 4 by fergus.henderson, Jul 29, 2008
I've applied the patch.
Status: Fixed
Sign in to add a comment

Hosted by Google Code