Returning the size file without read permission c++ -


i using piece of code

long filesize (const char * filename) {     ifstream file (filename, ios::in|ios::binary);     file.seekg (0, ios::end);     return file.tellg(); } 

in order return size of file in bytes. file without read permission results in returning -1. there way using c++ or c return size of file , directories , works on file without read permission? looking while fail find solid solution.

the current c++ standard library not offer possibility inquire size of file file system.

in future, when c++17 released, c++ standard library have have an api basic file system operations. using api, should not require read permission file (but need permission on parent directories in path, of course) although, don't think standard provides guarantees non-requirement of permissions:

return std::filesystem::file_size(filename); 

until upcoming standard supported standard library (some standard libraries have experimental support experimental/filesystem technical specification), need resort os specific api or a non-standard wrapper library.