summaryrefslogtreecommitdiff
path: root/src/basic/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-09-17 01:21:19 +0200
committerLennart Poettering <lennart@poettering.net>2015-09-22 16:30:24 +0200
commited0d40229bc536c424fad481e56afcaa1d0e38db (patch)
treeb0d311194508bf75059da687169f139706364d9d /src/basic/util.c
parentf6d9c616b6cccd561fa1db5f58106cbd534b9e34 (diff)
util: add safe_closedir() similar to safe_fclose()
Diffstat (limited to 'src/basic/util.c')
-rw-r--r--src/basic/util.c11
1 files changed, 11 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;