diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2014-10-13 08:16:51 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-10-13 08:16:51 -0400 |
commit | b7b6d29a5914f2a183545d3ed2bd4387da61956e (patch) | |
tree | f5c6c9ddd3e34147680e7b4d264a027ebc14b55d | |
parent | db7f2f6e89c7fcff8bb552129564018b3d6ac4b8 (diff) |
src/shared/util.c: more cosmetic changes
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r-- | src/shared/util.c | 75 |
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, |