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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user