diff --git a/CMakeLists.txt b/CMakeLists.txt index 0aa0d83..450121c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ target_include_directories( if(IS_TOP_PROJECT) # Enable C++11 for examples and tests if(ELFIO_BUILD_EXAMPLES OR ELFIO_BUILD_TESTS) - set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD 14) endif() if(ELFIO_BUILD_EXAMPLES) diff --git a/elfio/elfio.hpp b/elfio/elfio.hpp index d9d9945..28fe897 100644 --- a/elfio/elfio.hpp +++ b/elfio/elfio.hpp @@ -141,13 +141,19 @@ class elfio //------------------------------------------------------------------------------ bool load( const std::string& file_name, bool is_lazy = false ) noexcept { - std::ifstream stream; - stream.open( file_name.c_str(), std::ios::in | std::ios::binary ); - if ( !stream ) { + pstream = std::make_unique(); + pstream->open( file_name.c_str(), std::ios::in | std::ios::binary ); + if ( pstream == nullptr || !*pstream ) { return false; } - return load( stream, is_lazy ); + bool ret = load( *pstream, is_lazy ); + + if ( !is_lazy ) { + pstream.release(); + } + + return ret; } //------------------------------------------------------------------------------ @@ -1085,7 +1091,7 @@ class elfio //------------------------------------------------------------------------------ private: - std::ifstream* pstream = nullptr; + std::unique_ptr pstream = nullptr; std::unique_ptr header = nullptr; std::vector> sections_; std::vector> segments_;