1 /* 2 * Python file object IO handle functions 3 * 4 * Copyright (C) 2008-2021, 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 #if !defined( _PYOLECF_FILE_OBJECT_IO_HANDLE_H ) 23 #define _PYOLECF_FILE_OBJECT_IO_HANDLE_H 24 25 #include <common.h> 26 #include <types.h> 27 28 #include "pyolecf_libbfio.h" 29 #include "pyolecf_libcerror.h" 30 #include "pyolecf_python.h" 31 32 #if defined( __cplusplus ) 33 extern "C" { 34 #endif 35 36 typedef struct pyolecf_file_object_io_handle pyolecf_file_object_io_handle_t; 37 38 struct pyolecf_file_object_io_handle 39 { 40 /* The python file (like) object 41 */ 42 PyObject *file_object; 43 44 /* The access flags 45 */ 46 int access_flags; 47 }; 48 49 int pyolecf_file_object_io_handle_initialize( 50 pyolecf_file_object_io_handle_t **file_object_io_handle, 51 PyObject *file_object, 52 libcerror_error_t **error ); 53 54 int pyolecf_file_object_initialize( 55 libbfio_handle_t **handle, 56 PyObject *file_object, 57 libcerror_error_t **error ); 58 59 int pyolecf_file_object_io_handle_free( 60 pyolecf_file_object_io_handle_t **file_object_io_handle, 61 libcerror_error_t **error ); 62 63 int pyolecf_file_object_io_handle_clone( 64 pyolecf_file_object_io_handle_t **destination_file_object_io_handle, 65 pyolecf_file_object_io_handle_t *source_file_object_io_handle, 66 libcerror_error_t **error ); 67 68 int pyolecf_file_object_io_handle_open( 69 pyolecf_file_object_io_handle_t *file_object_io_handle, 70 int access_flags, 71 libcerror_error_t **error ); 72 73 int pyolecf_file_object_io_handle_close( 74 pyolecf_file_object_io_handle_t *file_object_io_handle, 75 libcerror_error_t **error ); 76 77 ssize_t pyolecf_file_object_read_buffer( 78 PyObject *file_object, 79 uint8_t *buffer, 80 size_t size, 81 libcerror_error_t **error ); 82 83 ssize_t pyolecf_file_object_io_handle_read( 84 pyolecf_file_object_io_handle_t *file_object_io_handle, 85 uint8_t *buffer, 86 size_t size, 87 libcerror_error_t **error ); 88 89 ssize_t pyolecf_file_object_write_buffer( 90 PyObject *file_object, 91 const uint8_t *buffer, 92 size_t size, 93 libcerror_error_t **error ); 94 95 ssize_t pyolecf_file_object_io_handle_write( 96 pyolecf_file_object_io_handle_t *file_object_io_handle, 97 const uint8_t *buffer, 98 size_t size, 99 libcerror_error_t **error ); 100 101 int pyolecf_file_object_seek_offset( 102 PyObject *file_object, 103 off64_t offset, 104 int whence, 105 libcerror_error_t **error ); 106 107 int pyolecf_file_object_get_offset( 108 PyObject *file_object, 109 off64_t *offset, 110 libcerror_error_t **error ); 111 112 off64_t pyolecf_file_object_io_handle_seek_offset( 113 pyolecf_file_object_io_handle_t *file_object_io_handle, 114 off64_t offset, 115 int whence, 116 libcerror_error_t **error ); 117 118 int pyolecf_file_object_io_handle_exists( 119 pyolecf_file_object_io_handle_t *file_object_io_handle, 120 libcerror_error_t **error ); 121 122 int pyolecf_file_object_io_handle_is_open( 123 pyolecf_file_object_io_handle_t *file_object_io_handle, 124 libcerror_error_t **error ); 125 126 int pyolecf_file_object_get_size( 127 PyObject *file_object, 128 size64_t *size, 129 libcerror_error_t **error ); 130 131 int pyolecf_file_object_io_handle_get_size( 132 pyolecf_file_object_io_handle_t *file_object_io_handle, 133 size64_t *size, 134 libcerror_error_t **error ); 135 136 #if defined( __cplusplus ) 137 } 138 #endif 139 140 #endif /* !defined( _PYOLECF_FILE_OBJECT_IO_HANDLE_H ) */ 141 142