(a general note on what’s good practice)
In C, 0 is false and !0 is true.
In the dim past there was an elsewhere where 0 was true and !0
was false. Why? Because there can be more than one error state
and this is usually more interesting than how many ways success
could have been acheived.
Well, that sucks too - there’s information on success that could
be useful (e.g. we succeeded, but only n bytes worth instead of
the m you asked for).
So, the way of <0 on failure and else success came about for
packing the maximum amount of information into the int that we
commonly return from functions (and usually fits nicely in a
register and it all leads to hugs, puppies and a warm feeling
inside).
So what do most people do on error? Return -1.
Hrrmm… this casually (if not totally) defeats the point. In any
function that does any real work, there’s going to be more than
one place where failure …
[Read more]