Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing error conditions - EINTR

In short, how do you unit test an error condition such as EINTR on a system call.

One particular example I'm working on, which could be a case all by itself, is whether it's necessary to call fclose again when it returns EOF with (errno==EINTR). The behavior depends on the implementation of fclose:

// Given an open FILE *fp
while (fclose(fp)==EOF && errno==EINTR) {
    errno = 0;
}

This call can be unsafe if fp freed when EINTR occurs. How can I test the error handling for when (errno==EINTR)?

like image 629
Michael Smith Avatar asked Oct 06 '08 22:10

Michael Smith


1 Answers

In this particular case, it's not safe to call fclose() again, as the C standard says the stream is disassociated from the file (and becomes indeterminate) even if the call fails.

like image 194
fizzer Avatar answered Nov 12 '22 01:11

fizzer