Using open, read, write means you have to worry about signal interaptions.
If the call was interrupted by a signal handler the functions will return -1 and set errno to EINTR.
So the proper way to close a file would be
while (retval = close(fd), retval == -1 && ernno == EINTR) ;