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