/src/libpff/libpff/libpff_reference_descriptor.c
Line | Count | Source |
1 | | /* |
2 | | * Reference descriptor functions |
3 | | * |
4 | | * Copyright (C) 2008-2025, 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_libcerror.h" |
27 | | #include "libpff_reference_descriptor.h" |
28 | | |
29 | | /* Creates a reference descriptor |
30 | | * Make sure the value reference_descriptor is referencing, is set to NULL |
31 | | * Returns 1 if successful or -1 on error |
32 | | */ |
33 | | int libpff_reference_descriptor_initialize( |
34 | | libpff_reference_descriptor_t **reference_descriptor, |
35 | | uint32_t value, |
36 | | libcerror_error_t **error ) |
37 | 122k | { |
38 | 122k | static char *function = "libpff_reference_descriptor_initialize"; |
39 | | |
40 | 122k | if( reference_descriptor == NULL ) |
41 | 0 | { |
42 | 0 | libcerror_error_set( |
43 | 0 | error, |
44 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
45 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
46 | 0 | "%s: invalid reference descriptor.", |
47 | 0 | function ); |
48 | |
|
49 | 0 | return( -1 ); |
50 | 0 | } |
51 | 122k | if( *reference_descriptor != NULL ) |
52 | 0 | { |
53 | 0 | libcerror_error_set( |
54 | 0 | error, |
55 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
56 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
57 | 0 | "%s: invalid reference descriptor value already set.", |
58 | 0 | function ); |
59 | |
|
60 | 0 | return( -1 ); |
61 | 0 | } |
62 | 122k | *reference_descriptor = memory_allocate_structure( |
63 | 122k | libpff_reference_descriptor_t ); |
64 | | |
65 | 122k | if( *reference_descriptor == NULL ) |
66 | 0 | { |
67 | 0 | libcerror_error_set( |
68 | 0 | error, |
69 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
70 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
71 | 0 | "%s: unable to create reference descriptor.", |
72 | 0 | function ); |
73 | |
|
74 | 0 | goto on_error; |
75 | 0 | } |
76 | 122k | if( memory_set( |
77 | 122k | *reference_descriptor, |
78 | 122k | 0, |
79 | 122k | sizeof( libpff_reference_descriptor_t ) ) == NULL ) |
80 | 0 | { |
81 | 0 | libcerror_error_set( |
82 | 0 | error, |
83 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
84 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
85 | 0 | "%s: unable to clear reference descriptor.", |
86 | 0 | function ); |
87 | |
|
88 | 0 | goto on_error; |
89 | 0 | } |
90 | 122k | ( *reference_descriptor )->value = value; |
91 | | |
92 | 122k | return( 1 ); |
93 | | |
94 | 0 | on_error: |
95 | 0 | if( *reference_descriptor != NULL ) |
96 | 0 | { |
97 | 0 | memory_free( |
98 | 0 | *reference_descriptor ); |
99 | |
|
100 | 0 | *reference_descriptor = NULL; |
101 | 0 | } |
102 | 0 | return( -1 ); |
103 | 122k | } |
104 | | |
105 | | /* Frees a reference descriptor |
106 | | * Returns 1 if successful or -1 on error |
107 | | */ |
108 | | int libpff_reference_descriptor_free( |
109 | | libpff_reference_descriptor_t **reference_descriptor, |
110 | | libcerror_error_t **error ) |
111 | 122k | { |
112 | 122k | static char *function = "libpff_reference_descriptor_free"; |
113 | | |
114 | 122k | if( reference_descriptor == 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 reference descriptor.", |
121 | 0 | function ); |
122 | |
|
123 | 0 | return( -1 ); |
124 | 0 | } |
125 | 122k | if( *reference_descriptor != NULL ) |
126 | 122k | { |
127 | 122k | memory_free( |
128 | 122k | *reference_descriptor ); |
129 | | |
130 | | *reference_descriptor = NULL; |
131 | 122k | } |
132 | 122k | return( 1 ); |
133 | 122k | } |
134 | | |