void test_fread_truncated_tail() { test_work_area_type * work_area = test_work_area_alloc("fortio_truncated2" ); { const size_t buffer_size = 1000; void * buffer = util_malloc( buffer_size ); { fortio_type * fortio = fortio_open_writer( "PRESSURE" , false , true ); fortio_fwrite_record( fortio , buffer , buffer_size ); fortio_fseek( fortio , 0 , SEEK_SET); util_ftruncate( fortio_get_FILE(fortio) , buffer_size + 4); fortio_fclose( fortio ); } test_assert_long_equal( util_file_size( "PRESSURE") , buffer_size + 4); { fortio_type * fortio = fortio_open_reader( "PRESSURE" , false , true ); test_assert_false( fortio_fread_buffer( fortio , buffer , buffer_size )); fortio_fclose( fortio ); } free( buffer ); } test_work_area_free( work_area ); }
static void ecl_sum_data_fwrite_unified_step( const ecl_sum_data_type * data , const char * ecl_case , bool fmt_case , int report_step) { char * filename = ecl_util_alloc_filename( NULL , ecl_case , ECL_UNIFIED_SUMMARY_FILE , fmt_case , 0 ); fortio_type * fortio = fortio_open_readwrite( filename , fmt_case , ECL_ENDIAN_FLIP ); int current_step = 1; if (report_step > 1) { while (true) { if (ecl_kw_fseek_kw( SEQHDR_KW , false , false , fortio )) { if (current_step == report_step) break; current_step++; } else { current_step++; break; } } } if (current_step == report_step) { // We found the position: long size = fortio_ftell( fortio ); util_ftruncate( fortio_get_FILE( fortio ) , size ); ecl_sum_data_fwrite_report__( data , report_step , fortio ); } else util_abort("%s: hmm could not locate the position for report step:%d in summary file:%s \n",__func__ , report_step , filename); fortio_fclose( fortio ); free( filename ); }