You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

211 lines
4.8 KiB

  1. /*
  2. * Data array entry functions
  3. *
  4. * Copyright (C) 2008-2019, 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. #include <common.h>
  22. #include <memory.h>
  23. #include <types.h>
  24. #include "libpff_data_array_entry.h"
  25. #include "libpff_libcerror.h"
  26. /* Creates a data array entry
  27. * Make sure the value data_array_entry is referencing, is set to NULL
  28. * Returns 1 if successful or -1 on error
  29. */
  30. int libpff_data_array_entry_initialize(
  31. libpff_data_array_entry_t **data_array_entry,
  32. libcerror_error_t **error )
  33. {
  34. static char *function = "libpff_data_array_entry_initialize";
  35. if( data_array_entry == NULL )
  36. {
  37. libcerror_error_set(
  38. error,
  39. LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
  40. LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
  41. "%s: invalid data array entry.",
  42. function );
  43. return( -1 );
  44. }
  45. if( *data_array_entry != NULL )
  46. {
  47. libcerror_error_set(
  48. error,
  49. LIBCERROR_ERROR_DOMAIN_RUNTIME,
  50. LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
  51. "%s: invalid data array entry value already set.",
  52. function );
  53. return( -1 );
  54. }
  55. *data_array_entry = memory_allocate_structure(
  56. libpff_data_array_entry_t );
  57. if( *data_array_entry == NULL )
  58. {
  59. libcerror_error_set(
  60. error,
  61. LIBCERROR_ERROR_DOMAIN_MEMORY,
  62. LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
  63. "%s: unable to create data array entry.",
  64. function );
  65. goto on_error;
  66. }
  67. if( memory_set(
  68. *data_array_entry,
  69. 0,
  70. sizeof( libpff_data_array_entry_t ) ) == NULL )
  71. {
  72. libcerror_error_set(
  73. error,
  74. LIBCERROR_ERROR_DOMAIN_MEMORY,
  75. LIBCERROR_MEMORY_ERROR_SET_FAILED,
  76. "%s: unable to clear data array entry.",
  77. function );
  78. goto on_error;
  79. }
  80. return( 1 );
  81. on_error:
  82. if( *data_array_entry != NULL )
  83. {
  84. memory_free(
  85. *data_array_entry );
  86. *data_array_entry = NULL;
  87. }
  88. return( -1 );
  89. }
  90. /* Frees a data array entry
  91. * Returns 1 if successful or -1 on error
  92. */
  93. int libpff_data_array_entry_free(
  94. libpff_data_array_entry_t **data_array_entry,
  95. libcerror_error_t **error )
  96. {
  97. static char *function = "libpff_data_array_entry_free";
  98. if( data_array_entry == NULL )
  99. {
  100. libcerror_error_set(
  101. error,
  102. LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
  103. LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
  104. "%s: invalid data array entry.",
  105. function );
  106. return( -1 );
  107. }
  108. if( *data_array_entry != NULL )
  109. {
  110. memory_free(
  111. *data_array_entry );
  112. *data_array_entry = NULL;
  113. }
  114. return( 1 );
  115. }
  116. /* Clones the data array entry
  117. * Returns 1 if successful or -1 on error
  118. */
  119. int libpff_data_array_entry_clone(
  120. libpff_data_array_entry_t **destination_data_array_entry,
  121. libpff_data_array_entry_t *source_data_array_entry,
  122. libcerror_error_t **error )
  123. {
  124. static char *function = "libpff_data_array_entry_clone";
  125. if( destination_data_array_entry == NULL )
  126. {
  127. libcerror_error_set(
  128. error,
  129. LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
  130. LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
  131. "%s: invalid destination data array entry.",
  132. function );
  133. return( -1 );
  134. }
  135. if( *destination_data_array_entry != NULL )
  136. {
  137. libcerror_error_set(
  138. error,
  139. LIBCERROR_ERROR_DOMAIN_RUNTIME,
  140. LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
  141. "%s: invalid destination data array entry already set.",
  142. function );
  143. return( -1 );
  144. }
  145. if( source_data_array_entry == NULL )
  146. {
  147. *destination_data_array_entry = NULL;
  148. return( 1 );
  149. }
  150. *destination_data_array_entry = memory_allocate_structure(
  151. libpff_data_array_entry_t );
  152. if( *destination_data_array_entry == NULL )
  153. {
  154. libcerror_error_set(
  155. error,
  156. LIBCERROR_ERROR_DOMAIN_MEMORY,
  157. LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
  158. "%s: unable to create destination data array entry.",
  159. function );
  160. goto on_error;
  161. }
  162. if( memory_copy(
  163. *destination_data_array_entry,
  164. source_data_array_entry,
  165. sizeof( libpff_data_array_entry_t ) ) == NULL )
  166. {
  167. libcerror_error_set(
  168. error,
  169. LIBCERROR_ERROR_DOMAIN_MEMORY,
  170. LIBCERROR_MEMORY_ERROR_COPY_FAILED,
  171. "%s: unable to copy data array entry.",
  172. function );
  173. goto on_error;
  174. }
  175. return( 1 );
  176. on_error:
  177. if( *destination_data_array_entry != NULL )
  178. {
  179. memory_free(
  180. *destination_data_array_entry );
  181. *destination_data_array_entry = NULL;
  182. }
  183. return( -1 );
  184. }