MCPcopy Create free account
hub / github.com/F-Stack/f-stack / loadFile_orDie

Function loadFile_orDie

freebsd/contrib/zstd/examples/common.h:180–193  ·  view source on GitHub ↗

! loadFile_orDie() : * load file into buffer (memory). * * Note: This function will send an error to stderr and exit if it * cannot read data from the given file path. * * @return If successful this function will load file into buffer and * return file size, otherwise it will printout an error to stderr and exit. */

Source from the content-addressed store, hash-verified

178 * return file size, otherwise it will printout an error to stderr and exit.
179 */
180static size_t loadFile_orDie(const char* fileName, void* buffer, size_t bufferSize)
181{
182 size_t const fileSize = fsize_orDie(fileName);
183 CHECK(fileSize <= bufferSize, "File too large!");
184
185 FILE* const inFile = fopen_orDie(fileName, "rb");
186 size_t const readSize = fread(buffer, 1, fileSize, inFile);
187 if (readSize != (size_t)fileSize) {
188 fprintf(stderr, "fread: %s : %s \n", fileName, strerror(errno));
189 exit(ERROR_fread);
190 }
191 fclose(inFile); /* can't fail, read only */
192 return fileSize;
193}
194
195/*! mallocAndLoadFile_orDie() :
196 * allocate memory buffer and then load file into it.

Callers 2

compressFile_orDieFunction · 0.85
mallocAndLoadFile_orDieFunction · 0.85

Calls 2

fsize_orDieFunction · 0.85
fopen_orDieFunction · 0.85

Tested by

no test coverage detected