From b7b6d29a5914f2a183545d3ed2bd4387da61956e Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Mon, 13 Oct 2014 08:16:51 -0400 Subject: src/shared/util.c: more cosmetic changes Signed-off-by: Anthony G. Basile --- src/shared/util.c | 75 ++++++++++++++++++++++++++++--------------------------- 1 file 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, -- cgit v1.2.3-54-g00ecf