summaryrefslogtreecommitdiff
path: root/src/basic/util.c
diff options
context:
space:
mode:
authorDaniel Mack <github@zonque.org>2015-09-09 15:45:03 +0200
committerDaniel Mack <github@zonque.org>2015-09-09 15:45:03 +0200
commit01da201420edfb2a57e384f109def05f25429305 (patch)
tree1c3090f3b5200ba62613285553afa0f7a6d30b9a /src/basic/util.c
parent37b76fd3ee5a03d76786e7bd1e0f8596e6ce47d6 (diff)
parent74ca738f6a01fb5fc19c5c3899f5cb1fdc1d7f68 (diff)
Merge pull request #1218 from poettering/safe-fclose
util: introduce safe_fclose() and port everything over to it
Diffstat (limited to 'src/basic/util.c')
-rw-r--r--src/basic/util.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/basic/util.c b/src/basic/util.c
index 3e41e6ad41..f7b2edf88c 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -327,6 +327,33 @@ void close_many(const int fds[], unsigned n_fd) {
safe_close(fds[i]);
}
+int fclose_nointr(FILE *f) {
+ assert(f);
+
+ /* Same as close_nointr(), but for fclose() */
+
+ if (fclose(f) == 0)
+ return 0;
+
+ if (errno == EINTR)
+ return 0;
+
+ return -errno;
+}
+
+FILE* safe_fclose(FILE *f) {
+
+ /* Same as safe_close(), but for fclose() */
+
+ if (f) {
+ PROTECT_ERRNO;
+
+ assert_se(fclose_nointr(f) != EBADF);
+ }
+
+ return NULL;
+}
+
int unlink_noerrno(const char *path) {
PROTECT_ERRNO;
int r;