| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include <stdio.h> | ||
| 8 | #include "check_png.h" | ||
| 9 | |||
| 10 | #define PNG_BYTES_TO_CHECK 4 | ||
| 11 | |||
| 12 | ///Check if the given filename is a png file | ||
| 13 | /** @param fileName : name of the file to be checked | ||
| 14 | * @return true if the given file is a png, false if not | ||
| 15 | */ | ||
| 16 | 3 | bool check_is_png(const PPath & fileName){ | |
| 17 | unsigned char buf[PNG_BYTES_TO_CHECK]; | ||
| 18 | |||
| 19 |
1/1✓ Branch 0 (3→4) taken 3 times.
|
3 | FILE * fp = fopen(fileName.c_str(), "rb"); |
| 20 | /* Open the prospective PNG file. */ | ||
| 21 |
2/2✓ Branch 0 (4→5) taken 2 times.
✓ Branch 1 (4→6) taken 1 times.
|
3 | if(fp == NULL){return false;} |
| 22 | |||
| 23 | /* Read in some of the signature bytes. */ | ||
| 24 |
2/3✓ Branch 0 (6→7) taken 1 times.
✗ Branch 2 (7→8) not taken.
✓ Branch 3 (7→10) taken 1 times.
|
1 | if(fread(buf, 1, PNG_BYTES_TO_CHECK, fp) != PNG_BYTES_TO_CHECK){ |
| 25 | ✗ | fclose(fp); | |
| 26 | ✗ | return false; | |
| 27 | } | ||
| 28 | /* Compare the first PNG_BYTES_TO_CHECK bytes of the signature. | ||
| 29 | * Return nonzero (true) if they match. | ||
| 30 | */ | ||
| 31 |
1/1✓ Branch 0 (10→11) taken 1 times.
|
1 | bool b(!png_sig_cmp(buf, 0, PNG_BYTES_TO_CHECK)); |
| 32 |
1/1✓ Branch 0 (11→12) taken 1 times.
|
1 | fclose(fp); |
| 33 | 1 | return b; | |
| 34 | } | ||
| 35 | |||
| 36 | |||
| 37 |