readclose − open a file, copy it’s content into a buffer, and close the file
#include "readclose.h"
int readclose(int fd,stralloc *sa,unsigned int bufsize);
int readclose_append(int fd,stralloc *sa,unsigned int bufsize);
int openreadclose(const char *fd,stralloc *sa,unsigned int bufsize);
readclose_append opens a file with file descriptor fd and appends the result into a pre-allocated buffer stralloc *sa while reading bufsize bytes of data-chunks consecutive until reaching EOF. The file descriptor is closed then and the number of bytes read/stored is returned.
readclose opens a file with file descriptor fd and stores the result into a pre-allocated buffer stralloc *sa while reading bufsize bytes of data-chunks until EOF and closing the file. On return, the number of bytes read/stored is given.
openreadclose performs the same action like readclose but now instead of the file desriptor fd the file name fn is given.
The readclose routines substitude the former slurp called functions. In addition, the macros slurp and slurpclose are provided, allowing to keep the code unaltered while simply including the header readclose.h.
stralloc(3)