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

Attachment: pgpVzEBiZPzCZ.pgp
Description: PGP signature

-- 
http://linuxfromscratch.org/mailman/listinfo/hlfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to