mark at kingant.net
Sat Feb 24 16:59:43 EST 2007
On Sat, 24 Feb 2007 15:56:59 -0500, Evan Schoenberg wrote
> On Feb 24, 2007, at 3:25 PM, markdoliner at pidgin.im wrote:
> > Evan, was this line necessary? It causes the following warning
> > for me when compiling:
> > eventloop.c: In function 'gaim_input_get_error':
> > eventloop.c:70: warning: ISO C90 forbids mixed declarations and code
> I included it not because I'd seen a need but rather because the
> usage for errno in the page I found via Google  when I was
> trying to figure out why errno is used the way it is in proxy.c says:
> "An application that needs to examine the value of errno to
> determine the error should set it to 0 before a function call, then
> inspect it before a subsequent function call."
> I see no reason errno needs to be used at all, though, as getsockopt
> () returns the value directly into the pointer we pass.
>  http://www.opengroup.org/onlinepubs/009695399/functions/errno.html
For most functions that deal with errno, the function will set errno to the
error number AND return non-zero (or something similar). So usually you can
just say, "Oh, this function returned non-zero, therefore something went wrong
and I should look at errno to figure out what happened."
There are a few functions that aren't able to signal an error based on just
the return value, so for those functions it's necessary to set errno to 0
before calling them, and then check if errno != 0 afterwards. readdir() is
the only one I can think of.
More information about the Cabal