summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c75
1 files changed, 38 insertions, 37 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 9672b7fcc0..5ad206a6c2 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -652,43 +652,6 @@ int flush_fd(int fd) {
}
}
-int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
- FILE *f;
- char *t;
- int fd;
-
- assert(path);
- assert(_f);
- assert(_temp_path);
-
- t = tempfn_xxxxxx(path);
- if (!t)
- return -ENOMEM;
-
-#if HAVE_DECL_MKOSTEMP
- fd = mkostemp_safe(t, O_WRONLY|O_CLOEXEC);
-#else
- fd = mkstemp_safe(t);
- fcntl(fd, F_SETFD, FD_CLOEXEC);
-#endif
- if (fd < 0) {
- free(t);
- return -errno;
- }
-
- f = fdopen(fd, "we");
- if (!f) {
- unlink(t);
- free(t);
- return -errno;
- }
-
- *_f = f;
- *_temp_path = t;
-
- return 0;
-}
-
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
uint8_t *p = buf;
ssize_t n = 0;
@@ -866,6 +829,44 @@ bool nulstr_contains(const char*nulstr, const char *needle) {
return false;
}
+int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
+ FILE *f;
+ char *t;
+ int fd;
+
+ assert(path);
+ assert(_f);
+ assert(_temp_path);
+
+ t = tempfn_xxxxxx(path);
+ if (!t)
+ return -ENOMEM;
+
+#if HAVE_DECL_MKOSTEMP
+ fd = mkostemp_safe(t, O_WRONLY|O_CLOEXEC);
+#else
+ fd = mkstemp_safe(t);
+ fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
+ if (fd < 0) {
+ free(t);
+ return -errno;
+ }
+
+ f = fdopen(fd, "we");
+ if (!f) {
+ unlink(t);
+ free(t);
+ return -errno;
+ }
+
+ *_f = f;
+ *_temp_path = t;
+
+ return 0;
+}
+
+
int get_user_creds(
const char **username,
uid_t *uid, gid_t *gid,