summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/util.c11
-rw-r--r--src/basic/util.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/src/basic/util.c b/src/basic/util.c
index e3b2af8e02..0c3ef2a68c 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -354,6 +354,17 @@ FILE* safe_fclose(FILE *f) {
return NULL;
}
+DIR* safe_closedir(DIR *d) {
+
+ if (d) {
+ PROTECT_ERRNO;
+
+ assert_se(closedir(d) >= 0 || errno != EBADF);
+ }
+
+ return NULL;
+}
+
int unlink_noerrno(const char *path) {
PROTECT_ERRNO;
int r;
diff --git a/src/basic/util.h b/src/basic/util.h
index 8abaa740b2..db5dd74770 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -151,6 +151,7 @@ void close_many(const int fds[], unsigned n_fd);
int fclose_nointr(FILE *f);
FILE* safe_fclose(FILE *f);
+DIR* safe_closedir(DIR *f);
int parse_size(const char *t, uint64_t base, uint64_t *size);