*: use _cleanup_close_ with fdopen() where trivial

Also convert these to use take_fdopen().
This commit is contained in:
Vito Caputo
2020-03-31 06:48:03 -07:00
parent 9f81a592c1
commit b46c3e4913
5 changed files with 16 additions and 25 deletions
+3 -5
View File
@@ -78,18 +78,16 @@ int mkostemp_safe(char *pattern) {
}
int fmkostemp_safe(char *pattern, const char *mode, FILE **ret_f) {
int fd;
_cleanup_close_ int fd = -1;
FILE *f;
fd = mkostemp_safe(pattern);
if (fd < 0)
return fd;
f = fdopen(fd, mode);
if (!f) {
safe_close(fd);
f = take_fdopen(&fd, mode);
if (!f)
return -errno;
}
*ret_f = f;
return 0;