summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-02-29 13:58:07 +0100
committerAlexander Larsson <alexl@redhat.com>2016-02-29 13:58:24 +0100
commit4d248d225ee2317857433a7eb8053297e1050ea8 (patch)
treea8031c18385a5d2160391a2ac5e7380799779206 /utils.c
parentcc582770f645edf46ead0d33676bf10bb942ead1 (diff)
downloadbubblewrap-4d248d225ee2317857433a7eb8053297e1050ea8.tar.gz
Break out load_file_data() helper
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/utils.c b/utils.c
index b459c63..a4b0e03 100644
--- a/utils.c
+++ b/utils.c
@@ -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) */