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