SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PngDef.hpp
Go to the documentation of this file.
1 
9 #ifndef PNGDEF_HPP_
10 #define PNGDEF_HPP_
11 
14 extern "C"{
15 #include <png.h>
16 #include <stdio.h>
17 }
18 
19 #define PNG_BYTES_TO_CHECK 4
20 /*
21  * \brief check if the file
22  */
23 int check_if_png(char *file_name, FILE **fp)
24 {
25  unsigned char buf[PNG_BYTES_TO_CHECK];
26 
27  /* Open the prospective PNG file. */
28  if ((*fp = fopen(file_name, "rb")) == NULL)
29  return 0;
30 
31  /* Read in some of the signature bytes */
32  if (fread(buf, 1, PNG_BYTES_TO_CHECK, *fp) != PNG_BYTES_TO_CHECK)
33  return 0;
34 
35  /* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.
36  Return nonzero (true) if they match */
37 
38  return(!png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK));
39 }
40 
46 #endif /* PNGDEF_HPP_ */