Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_fsize 4 #ifndef tools_fsize 5 #define tools_fsize 5 #define tools_fsize 6 6 7 #include <string> 7 #include <string> 8 #include <cstdio> 8 #include <cstdio> 9 9 10 namespace tools { 10 namespace tools { 11 namespace file { 11 namespace file { 12 12 13 inline bool size(const std::string& a_file,lon 13 inline bool size(const std::string& a_file,long& a_size){ 14 FILE* file = ::fopen(a_file.c_str(),"rb"); 14 FILE* file = ::fopen(a_file.c_str(),"rb"); 15 if(!file) { 15 if(!file) { 16 a_size = 0L; 16 a_size = 0L; 17 return false; 17 return false; 18 } 18 } 19 //::rewind(file); 19 //::rewind(file); 20 ::fseek(file,0L,SEEK_END); 20 ::fseek(file,0L,SEEK_END); 21 a_size = ::ftell(file); 21 a_size = ::ftell(file); 22 ::fclose(file); 22 ::fclose(file); 23 return true; 23 return true; 24 } 24 } 25 25 26 inline bool is_empty(const std::string& a_file 26 inline bool is_empty(const std::string& a_file){ 27 long sz; 27 long sz; 28 if(!size(a_file,sz)) return true; //if not e 28 if(!size(a_file,sz)) return true; //if not existing, consider it empty. 29 return (sz==0L)?true:false; 29 return (sz==0L)?true:false; 30 } 30 } 31 31 32 }} 32 }} 33 33 34 #endif 34 #endif