[PATCH] lib: libfile: Do not ignore errors in close()

Andrey Smirnov andrew.smirnov at gmail.com
Mon Jul 20 12:51:29 PDT 2015


>>       free(rw_buf);
>>       if (srcfd > 0)
>> -             close(srcfd);
>> +             err1 = close(srcfd);
>>       if (dstfd > 0)
>> -             close(dstfd);
>> +             err2 = close(dstfd);
>
> I agree that an error on closing the destination is an error for
> copy_file, but is an error on closing the source file an error for
> copy_file? We read everything from the source, so errors while closing
> the file should not be relevant.

I guess it depends on one's interpretation of what "success" means for
execution of copy_file(). I personally interpret it as: "the function
accomplished what is was supposed to do and all of the operations that
had to be done in order to do that completed without any errors", but
I can see how that being defined as "the function accomplished it's
main purpose with some possible minor failures" could work too. Since
I expect a call to close() to not fail for 99% of the time I don't see
any harm in checking for errors from both calls, but I don't feel very
strongly about the subject so if you want it I can remove the extra
check.

Andrey



More information about the barebox mailing list