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.
This commit is contained in:
Martin Willi
2014-01-23 15:55:32 +01:00
parent 595b6d9a82
commit 1c4a3459f7
10 changed files with 183 additions and 25 deletions
+5 -2
View File
@@ -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