Warning, /include/Geant4/tools/fileis is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_fileis
0005 #define tools_fileis
0006
0007 #include <cstdio>
0008 #include <cstring>
0009 #include <string>
0010
0011 namespace tools {
0012 namespace file {
0013
0014 inline bool signature(const std::string& a_file,unsigned char a_head[],unsigned int& a_num){ //it is assumed a_head[] can contain a_num chars.
0015 FILE* file = ::fopen(a_file.c_str(),"rb");
0016 if(!file) {a_num=0;return false;}
0017 a_num = (unsigned int)::fread(a_head,1,a_num,file);
0018 ::fclose(file);
0019 return true;
0020 }
0021
0022 inline bool is_gzip(const std::string& a_file,bool& a_is){
0023 unsigned char head[4];
0024 {unsigned int num = 4;
0025 if(!signature(a_file,head,num)) {a_is = false;return false;}
0026 if(num!=4) {a_is = false;return true;}}
0027 if(head[0]!=31) {a_is = false;return true;}
0028 if(head[1]!=139) {a_is = false;return true;}
0029 a_is = true;
0030 return true;
0031 }
0032
0033 inline bool is_root(const std::string& a_file,bool& a_is){
0034 unsigned char head[4];
0035 {unsigned int num = 4;
0036 if(!signature(a_file,head,num)) {a_is = false;return false;}
0037 if(num!=4) {a_is = false;return true;}}
0038 if(head[0]!='r') {a_is = false;return true;}
0039 if(head[1]!='o') {a_is = false;return true;}
0040 if(head[2]!='o') {a_is = false;return true;}
0041 if(head[3]!='t') {a_is = false;return true;}
0042 a_is = true;
0043 return true;
0044 }
0045
0046 }}
0047
0048 #endif