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