[illumos-Developer] Review for 89: Bug uu_list_find() leaves error unset when successfully returning NULL

Jason King jason.brian.king at gmail.com
Thu Jan 20 06:57:44 PST 2011


On Thu, Jan 20, 2011 at 3:53 AM, Joerg Schilling
<Joerg.Schilling at fokus.fraunhofer.de> wrote:
> Eric Schrock <eric.schrock at delphix.com> wrote:
>
>> Ugh, not the most pleasant API design, but nothing that can really be
>> changed, now.  A simple test case might be:
>>
>> 1. Create two lists, one with a NULL comparison routine, and a normal one.
>> 2. Try to search in the one with a NULL comparison routine (sets libuutil
>> error)
>> 3. Try to search for a non-existent entry in the normal one (should have a
>> zero errno)
>>
>> Otherwise looks OK to me.  This reminds me of strtol() and friends, where
>> most consumers are forced to preface it with 'errno = 0' to distinguish a
>> zero value from an invalid entry.  This seems like a better solution than
>> exporting that complexity to the user.
>
> The idea behind this concept is to never change errno in case there was no error.
>
> This allows to call any such function from inside other functions without being
> forced to save and restore the previous errno. Note that there are many
> situations where you like to return a previous "better" errno in case something
> fails.
>
> If you ever see a function where you believe you need to clear errno before
> calling the function, you found an ill-designed function. Functions should be
> designed in a way that allows to recognize whether there was an error or not
> without looking at errno. Errno is only needed to find out _which_ error
> happened.
>
> Unfortunately, there is no documentation for uu_list_find(), so it is hard to
> judge....

Well the library is 'private' (no header files were ever shipped, so
the only consumers should be other things in illumos), so if we want
to fix the API into something more useful/better, we can.



More information about the Developer mailing list