std-aux: add nm_clear_fd() helper

This commit is contained in:
Thomas Haller 2021-09-28 15:27:46 +02:00
parent 81ed762d46
commit f3def63fed
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -845,6 +845,19 @@ nm_close(int fd)
return r;
}
static inline bool
nm_clear_fd(int *p_fd)
{
int fd;
if (!p_fd || (fd = *p_fd) < 0)
return false;
*p_fd = -1;
nm_close(fd);
return true;
}
/*****************************************************************************/
/* Note: @value is only evaluated when *out_val is present.