qh_close()

Updated: April 19, 2023

Close a file and retry on EINTR

Synopsis:

#include <qh/io.h>
int qh_close(int fd)

Arguments:

fd
The file descriptor of the file to close (just like the one that would otherwise be passed to the close() function), or -1 (in which case the function does not call close() and returns successfully).

Library:

qh

Description:

When close() is called and it returns an error with errno set to EINTR, the caller is responsible for calling it again; otherwise, the file descriptor does not get closed, which creates a file descriptor leak. This function handles this task for the caller and also handles cases where the file descriptor is -1, which would otherwise require the caller to wrap the close() call.

This function never returns EINTR.

Returns:

EOK on success or a standard errno on failure (errno is set).