/src/libpff/libpff/libpff_column_definition.c
Line | Count | Source |
1 | | /* |
2 | | * Column definition functions |
3 | | * |
4 | | * Copyright (C) 2008-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 <memory.h> |
24 | | #include <types.h> |
25 | | |
26 | | #include "libpff_column_definition.h" |
27 | | #include "libpff_libcerror.h" |
28 | | #include "libpff_table.h" |
29 | | #include "libpff_types.h" |
30 | | |
31 | | /* Creates a column definition |
32 | | * Make sure the value column_definition is referencing, is set to NULL |
33 | | * Returns 1 if successful or -1 on error |
34 | | */ |
35 | | int libpff_column_definition_initialize( |
36 | | libpff_column_definition_t **column_definition, |
37 | | libcerror_error_t **error ) |
38 | 21.1k | { |
39 | 21.1k | static char *function = "libpff_column_definition_initialize"; |
40 | | |
41 | 21.1k | if( column_definition == NULL ) |
42 | 0 | { |
43 | 0 | libcerror_error_set( |
44 | 0 | error, |
45 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
46 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
47 | 0 | "%s: invalid column_definition.", |
48 | 0 | function ); |
49 | |
|
50 | 0 | return( -1 ); |
51 | 0 | } |
52 | 21.1k | if( *column_definition != NULL ) |
53 | 0 | { |
54 | 0 | libcerror_error_set( |
55 | 0 | error, |
56 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
57 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
58 | 0 | "%s: invalid column definition value already set.", |
59 | 0 | function ); |
60 | |
|
61 | 0 | return( -1 ); |
62 | 0 | } |
63 | 21.1k | *column_definition = memory_allocate_structure( |
64 | 21.1k | libpff_column_definition_t ); |
65 | | |
66 | 21.1k | if( *column_definition == NULL ) |
67 | 0 | { |
68 | 0 | libcerror_error_set( |
69 | 0 | error, |
70 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
71 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
72 | 0 | "%s: unable to create column definition.", |
73 | 0 | function ); |
74 | |
|
75 | 0 | goto on_error; |
76 | 0 | } |
77 | 21.1k | if( memory_set( |
78 | 21.1k | *column_definition, |
79 | 21.1k | 0, |
80 | 21.1k | sizeof( libpff_column_definition_t ) ) == NULL ) |
81 | 0 | { |
82 | 0 | libcerror_error_set( |
83 | 0 | error, |
84 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
85 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
86 | 0 | "%s: unable to clear column definition.", |
87 | 0 | function ); |
88 | |
|
89 | 0 | goto on_error; |
90 | 0 | } |
91 | 21.1k | return( 1 ); |
92 | | |
93 | 0 | on_error: |
94 | 0 | if( *column_definition != NULL ) |
95 | 0 | { |
96 | 0 | memory_free( |
97 | 0 | *column_definition ); |
98 | |
|
99 | 0 | *column_definition = NULL; |
100 | 0 | } |
101 | 0 | return( -1 ); |
102 | 21.1k | } |
103 | | |
104 | | /* Frees a column definition |
105 | | * Returns 1 if successful or -1 on error |
106 | | */ |
107 | | int libpff_column_definition_free( |
108 | | libpff_column_definition_t **column_definition, |
109 | | libcerror_error_t **error ) |
110 | 21.1k | { |
111 | 21.1k | static char *function = "libpff_column_definition_free"; |
112 | 21.1k | int result = 1; |
113 | | |
114 | 21.1k | if( column_definition == NULL ) |
115 | 0 | { |
116 | 0 | libcerror_error_set( |
117 | 0 | error, |
118 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
119 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
120 | 0 | "%s: invalid column definition.", |
121 | 0 | function ); |
122 | |
|
123 | 0 | return( -1 ); |
124 | 0 | } |
125 | 21.1k | if( *column_definition != NULL ) |
126 | 21.1k | { |
127 | | /* The name_to_id_map_entry reference is freed elsewhere |
128 | | */ |
129 | 21.1k | if( ( *column_definition )->record_entry_values_table != NULL ) |
130 | 0 | { |
131 | 0 | if( libpff_table_free( |
132 | 0 | &( ( *column_definition )->record_entry_values_table ), |
133 | 0 | error ) != 1 ) |
134 | 0 | { |
135 | 0 | libcerror_error_set( |
136 | 0 | error, |
137 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
138 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
139 | 0 | "%s: unable to free record entry values table.", |
140 | 0 | function ); |
141 | |
|
142 | 0 | result = -1; |
143 | 0 | } |
144 | 0 | } |
145 | 21.1k | memory_free( |
146 | 21.1k | *column_definition ); |
147 | | |
148 | | *column_definition = NULL; |
149 | 21.1k | } |
150 | 21.1k | return( result ); |
151 | 21.1k | } |
152 | | |