Attribute warn_unused_result

Alex Merry alexander.merry at ccc.ox.ac.uk
Fri Aug 25 11:57:00 PDT 2006


On Fri, Aug 25, 2006 at 01:56:56PM -0400, Robert Connolly wrote:
> Wrapping the chdir call in an if statement is much better. It gives the 
> program a contingency plan if the call fails, regardless of how unlikely that 
> is. It's also really easy to implement.
> 
> Would it be better to use 'if != 0' rather than 'if == -1'? If chdir() fails 
> it returns -1, but if libc fails to call chdir() I'm not sure about the 
> return value, it might be something else. 0 is only returned on success. Not 
> just for chdir(), but in a general sense.

Probably. I'm not entirely sure _what_ would happen if libc failed to
call chdir. But you're right, it is better practice to check for success
than failure, in case it fails in ways you weren't expecting.

Alex :-)


-- 
Pippin
Computer Monkey to the Pelican
www.oxrev.org.uk, www.corpusjcr.org, www.rev.org.uk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.linuxfromscratch.org/pipermail/hlfs-dev/attachments/20060825/b90b0db8/attachment.sig>


More information about the hlfs-dev mailing list