PhoenixPNG  0.1.0
Set of tools to ease use of png file
Loading...
Searching...
No Matches
check_png.cpp
Go to the documentation of this file.
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
13
16bool check_is_png(const PPath & fileName){
17 unsigned char buf[PNG_BYTES_TO_CHECK];
18
19 FILE * fp = fopen(fileName.c_str(), "rb");
20 /* Open the prospective PNG file. */
21 if(fp == NULL){return false;}
22
23 /* Read in some of the signature bytes. */
24 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 bool b(!png_sig_cmp(buf, 0, PNG_BYTES_TO_CHECK));
32 fclose(fp);
33 return b;
34}
35
36
bool check_is_png(const PPath &fileName)
Check if the given filename is a png file.
Definition check_png.cpp:16
#define PNG_BYTES_TO_CHECK
Definition check_png.cpp:10