From 1c4a3459f72da4391c1befe22e62356d838af46d Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Thu, 21 Nov 2013 12:19:20 +0100 Subject: chunk: Use dynamically allocated buffer in chunk_from_fd() When acting on files, we can use fstat() to estimate the buffer size. On non-file FDs, we dynamically increase an allocated buffer. Additionally we slightly change the function signature to properly handle zero-length files and add appropriate unit tests. --- src/libstrongswan/utils/chunk.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/libstrongswan/utils/chunk.h') diff --git a/src/libstrongswan/utils/chunk.h b/src/libstrongswan/utils/chunk.h index 92a96ffba..1228da30e 100644 --- a/src/libstrongswan/utils/chunk.h +++ b/src/libstrongswan/utils/chunk.h @@ -102,10 +102,13 @@ bool chunk_write(chunk_t chunk, char *path, char *label, mode_t mask, bool force /** * Store data read from FD into a chunk * + * On error, errno is set appropriately. + * * @param fd file descriptor to read from - * @return chunk or chunk_empty on failure + * @param chunk chunk receiving allocated buffer + * @return TRUE if successful, FALSE on failure */ -chunk_t chunk_from_fd(int fd); +bool chunk_from_fd(int fd, chunk_t *chunk); /** * mmap() a file to a chunk -- cgit v1.2.3