The check_close function

#include "/package/prog/prjlibs/include/check_close.h"

type_status check_close(type_fd fd);

  if (check_close(fd)!=0) perror("close failed");

The check_close() function is a wrapper around close(), closing a file descriptor. POSIX says that if a signal is caught, close() can return -1 with EINTR, and the file descriptor may or may not be closed. So naively retrying after EINTR may result in -1 with EBADF if the descriptor was actually closed the first time. check_close() retries after EINTR, but will not produce a spurious EBADF.

Note that retrying after EINTR is not appropriate in a multithreaded program that opens and closes descriptors from more than one thread and catches signals. If close() fails with EINTR but the descriptor was actually closed, then it's possible that another thread could open a new file with the same descriptor number, which would then be closed on a retry.

To link your program with the check_close function, add /package/prog/prjlibs/library/check_close.a to the end of the link command line.