mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-06 10:40:11 +01:00
util: add xclose(fd) to close-and-reset an fd
This prevents accidentally leaving the fd set after closing. And it includes the -1 check so we don't need this everywhere ourselves (not that we use it right now but valgrind likes to complain about this). Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1067>
This commit is contained in:
parent
a61c876412
commit
d3922661ba
1 changed files with 10 additions and 0 deletions
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "util-strings.h"
|
||||
|
|
@ -52,3 +53,12 @@ mkdir_p(const char *dir)
|
|||
|
||||
return (rc == -1 && errno != EEXIST) ? -errno : 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
xclose(int *fd)
|
||||
{
|
||||
if (*fd != -1) {
|
||||
close(*fd);
|
||||
*fd = -1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue