 
	
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] Suggestion: Improve hypercall Interface to get real return value
 On 05/12/12 11:05, George Dunlap wrote: On Wed, Dec 5, 2012 at 6:21 AM, Yanzhang Li <liyz@xxxxxxxxxx 
<mailto:liyz@xxxxxxxxxx>> wrote:
I think returning -1 instead of "the error" allows for simpler code when 
you do something like this:
int func()
{
     FILE *f = fopen(...);
     if(!f) return -1;
     while(...)
     {
        if (fread(f, ...) < 0)
        {
           fclose(f);
           return -1;
         }
         ...
        if (...)
           if (fwrite(f, ...) < 0)
           {
              fclose(f);
              return -1;
           }
     }
     fclose(f);
     return 0;
}
Now, we don't need extra code to "remember the errno from the failing 
function". [And I'm assuming here that fclose isn't "interfering" with 
the errno - if you REALLY need to know for sure what the errno was at 
fread or fwrite, you still need to "remember errno".(Note that some functions do not return -1 for failure in the above code, but for example NULL, and some function would not be able to return -errno, as that may well be a "valid" return value - so keeping the interface as alike as possible is a good idea) -- Mats -George _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel 
 
 | 
|  | Lists.xenproject.org is hosted with RackSpace, monitoring our |