Blame view

stim/util/filesize.h 663 Bytes
91d472ac   David Mayerich   added file_size f...
1
2
3
4
5
  #ifndef STIM_UTIL_FILESIZE_H
  #define STIM_UTIL_FILESIZE_H
  
  #ifdef _WIN32
  #include <Windows.h>
90eae717   David Mayerich   added filesize ch...
6
7
8
  #else
  #include <sys/types.h>
  #include <sys/stat.h>
91d472ac   David Mayerich   added file_size f...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #endif
  
  namespace stim{
  static size_t file_size(std::string filename){
  #ifdef _WIN32
  	HANDLE hFile = CreateFile(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  	if(hFile == INVALID_HANDLE_VALUE) return 0;
  	LARGE_INTEGER size;
  	if(!GetFileSizeEx(hFile, &size)){
  		CloseHandle(hFile);
  		return 0;
  	}
  	CloseHandle(hFile);
  	return (size_t)size.QuadPart;
90eae717   David Mayerich   added filesize ch...
23
24
25
26
  #else
  	struct stat sb;
  	stat(filename.c_str(), &sb);
  	return sb.st_size;
91d472ac   David Mayerich   added file_size f...
27
28
29
30
31
32
33
  #endif
  }
  
  }	//end namespace stim
  
  
  
90eae717   David Mayerich   added filesize ch...
34
  #endif