[lib] owl_close_fd(): handle negative fd
This commit is contained in:
parent
fe84a5f097
commit
c567592167
|
@ -413,6 +413,8 @@ float owl_swap_float(const float f)
|
|||
|
||||
/**
|
||||
* Opens a UDP transmission socket and returns its descriptor.
|
||||
* Uppon error, a message is displayed and a negative error code is
|
||||
* returned.
|
||||
*
|
||||
* @param[in] server_address The server's IP address.
|
||||
* @param[in] server_port The listening port on the server.
|
||||
|
@ -585,15 +587,16 @@ void owl_sigterm_handler(const int num)
|
|||
/**
|
||||
* Closes the file descriptor `fd`.
|
||||
* `fd` must be passed as an int pointer (`int*`). If `fd` is `NULL`,
|
||||
* nothing will be done. Uppon error, a message is displayed on the
|
||||
* standard error.
|
||||
* or if the pointed value is negative, nothing will be done.
|
||||
* Uppon error, a message is displayed on the standard error.
|
||||
*/
|
||||
void owl_close_fd(void *const fd)
|
||||
{
|
||||
if (fd == NULL)
|
||||
const int *const file_desc = fd;
|
||||
|
||||
if (file_desc == NULL || *file_desc < 0)
|
||||
return ;
|
||||
|
||||
const int *const file_desc = fd ;
|
||||
if (close(*file_desc) != 0)
|
||||
perror("Error closing file descriptor") ;
|
||||
#ifndef NDEBUG
|
||||
|
|
Loading…
Reference in New Issue