returns negative value on error. This should be pure C compatible, so no fstat. */
| 343 | |
| 344 | /* returns negative value on error. This should be pure C compatible, so no fstat. */ |
| 345 | static long lodepng_filesize(const char* filename) { |
| 346 | FILE* file; |
| 347 | long size; |
| 348 | file = fopen(filename, "rb"); |
| 349 | if(!file) return -1; |
| 350 | |
| 351 | if(fseek(file, 0, SEEK_END) != 0) { |
| 352 | fclose(file); |
| 353 | return -1; |
| 354 | } |
| 355 | |
| 356 | size = ftell(file); |
| 357 | /* It may give LONG_MAX as directory size, this is invalid for us. */ |
| 358 | if(size == LONG_MAX) size = -1; |
| 359 | |
| 360 | fclose(file); |
| 361 | return size; |
| 362 | } |
| 363 | |
| 364 | /* load file into buffer that already has the correct allocated size. Returns error code.*/ |
| 365 | static unsigned lodepng_buffer_file(unsigned char* out, size_t size, const char* filename) { |
no outgoing calls
no test coverage detected