/* Retrieves the size of the file object * Make sure to hold the GIL state before calling this function * Returns 1 if successful or -1 on error */ int pyewf_file_object_get_size( PyObject *file_object, size64_t *size, libcerror_error_t **error ) { PyObject *method_name = NULL; PyObject *method_result = NULL; static char *function = "pyewf_file_object_get_size"; if( file_object == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file object.", function ); return( -1 ); } if( size == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid size.", function ); return( -1 ); } #if PY_MAJOR_VERSION >= 3 method_name = PyUnicode_FromString( "get_size" ); #else method_name = PyString_FromString( "get_size" ); #endif PyErr_Clear(); method_result = PyObject_CallMethodObjArgs( file_object, method_name, NULL ); if( PyErr_Occurred() ) { pyewf_error_fetch( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve size of file object.", function ); goto on_error; } if( method_result == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: missing method result.", function ); goto on_error; } if( pyewf_integer_unsigned_copy_to_64bit( method_result, size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to convert method result into size of file object.", function ); goto on_error; } Py_DecRef( method_result ); Py_DecRef( method_name ); return( 1 ); on_error: if( method_result != NULL ) { Py_DecRef( method_result ); } if( method_name != NULL ) { Py_DecRef( method_name ); } return( -1 ); }
/* Retrieves the size of the file object * Make sure to hold the GIL state before calling this function * Returns 1 if successful or -1 on error */ int pyewf_file_object_get_size( PyObject *file_object, size64_t *size, libcerror_error_t **error ) { PyObject *exception_string = NULL; PyObject *exception_traceback = NULL; PyObject *exception_type = NULL; PyObject *exception_value = NULL; PyObject *method_name = NULL; PyObject *method_result = NULL; char *error_string = NULL; static char *function = "pyewf_file_object_get_size"; if( file_object == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file object.", function ); return( -1 ); } if( size == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid size.", function ); return( -1 ); } method_name = PyString_FromString( "get_size" ); PyErr_Clear(); method_result = PyObject_CallMethodObjArgs( file_object, method_name, NULL ); if( PyErr_Occurred() ) { PyErr_Fetch( &exception_type, &exception_value, &exception_traceback ); exception_string = PyObject_Repr( exception_value ); error_string = PyString_AsString( exception_string ); if( error_string != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve size of file object with error: %s.", function, error_string ); } else { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve size of file object.", function ); } Py_DecRef( exception_string ); goto on_error; } if( pyewf_integer_unsigned_copy_to_64bit( method_result, size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to convert method result into size of file object.", function ); goto on_error; } Py_DecRef( method_result ); Py_DecRef( method_name ); return( 1 ); on_error: if( method_result != NULL ) { Py_DecRef( method_result ); } if( method_name != NULL ) { Py_DecRef( method_name ); } return( -1 ); }