diff options
author | Alexander Larsson <alexl@redhat.com> | 2016-02-29 13:58:07 +0100 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2016-02-29 13:58:24 +0100 |
commit | 4d248d225ee2317857433a7eb8053297e1050ea8 (patch) | |
tree | a8031c18385a5d2160391a2ac5e7380799779206 /utils.c | |
parent | cc582770f645edf46ead0d33676bf10bb942ead1 (diff) | |
download | bubblewrap-4d248d225ee2317857433a7eb8053297e1050ea8.tar.gz |
Break out load_file_data() helper
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 29 |
1 files changed, 20 insertions, 9 deletions
@@ -414,23 +414,16 @@ copy_file (const char *src_path, return res; } - /* Sets errno on error (== NULL) */ char * -load_file_at (int dirfd, - const char *path) +load_file_data (int fd) { - int fd; cleanup_free char *data = NULL; ssize_t data_read; ssize_t data_len; ssize_t res; int errsv; - fd = openat (dirfd, path, O_CLOEXEC | O_RDONLY); - if (fd == -1) - return NULL; - data_read = 0; data_len = 4080; data = xmalloc (data_len); @@ -461,11 +454,29 @@ load_file_at (int dirfd, data[data_read] = 0; + return steal_pointer (&data); +} + +/* Sets errno on error (== NULL) */ +char * +load_file_at (int dirfd, + const char *path) +{ + int fd; + char *data; + int errsv; + + fd = openat (dirfd, path, O_CLOEXEC | O_RDONLY); + if (fd == -1) + return NULL; + + data = load_file_data (fd); + errsv = errno; close (fd); errno = errsv; - return steal_pointer (&data); + return data; } /* Sets errno on error (< 0) */ |