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>
#include <errno.h>
#include <libgen.h>
+#include <unistd.h>
#include <sys/stat.h>
#include "util-strings.h"
return (rc == -1 && errno != EEXIST) ? -errno : 0;
}
+
+static inline void
+xclose(int *fd)
+{
+ if (*fd != -1) {
+ close(*fd);
+ *fd = -1;
+ }
+}