Coverage Report

Created: 2026-07-25 07:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libregf/libregf/libregf_data_block_stream.c
Line
Count
Source
1
/*
2
 * Data block stream functions
3
 *
4
 * Copyright (C) 2009-2026, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <types.h>
24
25
#include "libregf_libbfio.h"
26
#include "libregf_libcerror.h"
27
#include "libregf_unused.h"
28
29
/* Reads the segment data into the buffer
30
 * Callback function for the value item data stream
31
 * Returns the number of bytes read or -1 on error
32
 */
33
ssize_t libregf_data_block_stream_read_segment_data(
34
         intptr_t *data_handle LIBREGF_ATTRIBUTE_UNUSED,
35
         libbfio_handle_t *file_io_handle,
36
         int segment_index LIBREGF_ATTRIBUTE_UNUSED,
37
         int segment_file_index LIBREGF_ATTRIBUTE_UNUSED,
38
         uint8_t *segment_data,
39
         size_t segment_data_size,
40
         uint32_t segment_flags LIBREGF_ATTRIBUTE_UNUSED,
41
         uint8_t read_flags LIBREGF_ATTRIBUTE_UNUSED,
42
         libcerror_error_t **error )
43
0
{
44
0
  static char *function = "libregf_data_block_stream_read_segment_data";
45
0
  ssize_t read_count    = 0;
46
47
0
  LIBREGF_UNREFERENCED_PARAMETER( data_handle )
48
0
  LIBREGF_UNREFERENCED_PARAMETER( segment_index )
49
0
  LIBREGF_UNREFERENCED_PARAMETER( segment_file_index )
50
0
  LIBREGF_UNREFERENCED_PARAMETER( segment_flags )
51
0
  LIBREGF_UNREFERENCED_PARAMETER( read_flags )
52
53
0
  read_count = libbfio_handle_read_buffer(
54
0
          file_io_handle,
55
0
          segment_data,
56
0
          segment_data_size,
57
0
          error );
58
59
0
  if( read_count != (ssize_t) segment_data_size )
60
0
  {
61
0
    libcerror_error_set(
62
0
     error,
63
0
     LIBCERROR_ERROR_DOMAIN_IO,
64
0
     LIBCERROR_IO_ERROR_READ_FAILED,
65
0
     "%s: unable to read segment data.",
66
0
     function );
67
68
0
    return( -1 );
69
0
  }
70
0
  return( read_count );
71
0
}
72
73
/* Seeks a certain segment offset
74
 * Callback function for the value item data stream
75
 * Returns the offset or -1 on error
76
 */
77
off64_t libregf_data_block_stream_seek_segment_offset(
78
         intptr_t *data_handle LIBREGF_ATTRIBUTE_UNUSED,
79
         libbfio_handle_t *file_io_handle,
80
         int segment_index LIBREGF_ATTRIBUTE_UNUSED,
81
         int segment_file_index LIBREGF_ATTRIBUTE_UNUSED,
82
         off64_t segment_offset,
83
         libcerror_error_t **error )
84
0
{
85
0
  static char *function = "libregf_data_block_stream_seek_segment_offset";
86
87
0
  LIBREGF_UNREFERENCED_PARAMETER( data_handle )
88
0
  LIBREGF_UNREFERENCED_PARAMETER( segment_index )
89
0
  LIBREGF_UNREFERENCED_PARAMETER( segment_file_index )
90
91
0
  segment_offset = libbfio_handle_seek_offset(
92
0
                    file_io_handle,
93
0
                    segment_offset,
94
0
                    SEEK_SET,
95
0
                    error );
96
97
0
  if( segment_offset == -1 )
98
0
  {
99
0
    libcerror_error_set(
100
0
     error,
101
0
     LIBCERROR_ERROR_DOMAIN_IO,
102
0
     LIBCERROR_IO_ERROR_READ_FAILED,
103
0
     "%s: unable to seek segment offset.",
104
0
     function );
105
106
0
    return( -1 );
107
0
  }
108
0
  return( segment_offset );
109
0
}
110