MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / lodepng_load_file

Function lodepng_load_file

src/lodepng.cpp:349–374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347#ifdef LODEPNG_COMPILE_DISK
348
349unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename)
350{
351 FILE* file;
352 long size;
353
354 /*provide some proper output values if error will happen*/
355 *out = 0;
356 *outsize = 0;
357
358 file = fopen(filename, "rb");
359 if(!file) return 78;
360
361 /*get filesize:*/
362 fseek(file , 0 , SEEK_END);
363 size = ftell(file);
364 rewind(file);
365
366 /*read contents of the file into the vector*/
367 *outsize = 0;
368 *out = (unsigned char*)lodepng_malloc((size_t)size);
369 if(size && (*out)) (*outsize) = fread(*out, 1, (size_t)size, file);
370
371 fclose(file);
372 if(!(*out) && size) return 83; /*the above malloc failed*/
373 return 0;
374}
375
376/*write given buffer to the file, overwriting the file, it doesn't append to it.*/
377unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename)

Callers 1

lodepng_decode_fileFunction · 0.85

Calls 1

lodepng_mallocFunction · 0.85

Tested by

no test coverage detected