LCOV - code coverage report
Current view: top level - vset/buffer/persistent/file - ad_resize_file.hpp (source / functions) Hit Total Coverage
Test: v-set-coverage.info Lines: 6 7 85.7 %
Date: 2019-09-12 Functions: 9 10 90.0 %

          Line data    Source code
       1             : //
       2             : // Author: Vladimir Migashko <migashko@gmail.com>, (C) 2012
       3             : //
       4             : // Copyright: See COPYING file that comes with this distribution
       5             : //
       6             : 
       7             : #ifndef VSET_VSET_BUFFER_PERSISTENT_FILE_AD_RESIZE_FILE_HPP
       8             : #define VSET_VSET_BUFFER_PERSISTENT_FILE_AD_RESIZE_FILE_HPP
       9             : 
      10             : #include <vset/buffer/tags.hpp>
      11             : #include <vset/buffer/persistent/tags.hpp>
      12             : #include <sys/stat.h>
      13             : #include <string.h>
      14             : #include <stdexcept>
      15             : #include <errno.h>
      16             : 
      17             : namespace vset { namespace buffer { namespace persistent{ namespace file{
      18             : 
      19          12 : struct ad_resize_file
      20             : {
      21             :   template<typename T>
      22          31 :   void operator()( T& t, size_t size )
      23             :   {
      24          31 :     size_t cur_size = t.get_aspect().template get<_file_size_>()(t);
      25          31 :     if ( size == cur_size )
      26             :     {
      27          33 :       return;
      28             :     }
      29             : 
      30          29 :     if ( -1 == ::ftruncate( t.get_aspect().template get<_descriptor_>(), static_cast<off_t>(size) ) )
      31             :     {
      32           0 :       throw std::runtime_error(strerror(errno));
      33             :     }
      34             :   }
      35             : };
      36             : 
      37             : }}}}
      38             : 
      39             : #endif

Generated by: LCOV version 1.10