Add fdopen_unlocked() wrapper

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2019-04-12 11:44:57 +02:00
parent 41f6e627d7
commit 02e23d1a1a
5 changed files with 37 additions and 17 deletions
+5 -6
View File
@@ -6,6 +6,7 @@
#include "alloc-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
#include "hexdecoct.h"
#include "macro.h"
@@ -42,16 +43,14 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
/* This assumes that returned FILE object is short-lived and used within the same single-threaded
* context and never shared externally, hence locking is not necessary. */
f = fdopen(fd, "w");
if (!f) {
unlink_noerrno(t);
r = fdopen_unlocked(fd, "w", &f);
if (r < 0) {
unlink(t);
free(t);
safe_close(fd);
return -errno;
return r;
}
(void) __fsetlocking(f, FSETLOCKING_BYCALLER);
*_f = f;
*_temp_path = t;