gfxd_sys/io.rs
1/* SPDX-FileCopyrightText: © 2025 Decompollaborate */
2/* SPDX-License-Identifier: MIT */
3
4//! Read and write `Gfx` packets.
5//!
6//! The input consists of any number of `Gfx` packets, and the output is the
7//! decompiled macros in plain-text. The endianness and microcode type of the
8//! input can be set using [`gfxd_endian`] and [`gfxd_target`].
9//!
10//! Several methods of doing I/O are available. No method is selected by
11//! default, meaning there will be no input, and any output will be discarded.
12//!
13//! [`gfxd_endian`]: crate::settings::gfxd_endian
14//! [`gfxd_target`]: crate::settings::gfxd_target
15
16use crate::ffi;
17
18use crate::ptr::{NonNullConst, NonNullMut};
19
20#[link(name = "gfxd", kind = "static")]
21extern "C" {
22 /// Use the buffer pointed to by `buf`, of `size` bytes.
23 pub fn gfxd_input_buffer(buf: Option<NonNullConst<ffi::c_void>>, size: ffi::c_int);
24
25 /// Use the buffer pointed to by `buf`, of `size` bytes.
26 pub fn gfxd_output_buffer(buf: Option<NonNullConst<ffi::c_char>>, size: ffi::c_int);
27
28 /// Use `read()` with the provided file descriptor, `fd`.
29 pub fn gfxd_input_fd(fd: ffi::c_int);
30
31 /// Use `write()` with the provided file descriptor, `fd`.
32 pub fn gfxd_output_fd(fd: ffi::c_int);
33
34 /// Use the provided callback function, `fn`.
35 ///
36 /// `fn` should copy at most `count` bytes to/from `buf`, and return the
37 /// number of bytes actually copied.
38 ///
39 /// The input callback should return 0 to signal end of input.
40 pub fn gfxd_input_callback(fn_: Option<gfxd_input_fn_t>);
41
42 /// Use the provided callback function, `fn`.
43 ///
44 /// `fn` should copy at most `count` bytes to/from `buf`, and return the
45 /// number of bytes actually copied.
46 pub fn gfxd_output_callback(fn_: Option<gfxd_output_fn_t>);
47}
48
49pub type gfxd_input_fn_t =
50 unsafe extern "C" fn(buf: NonNullMut<ffi::c_void>, count: ffi::c_int) -> ffi::c_int;
51
52pub type gfxd_output_fn_t =
53 unsafe extern "C" fn(buf: NonNullConst<ffi::c_char>, count: ffi::c_int) -> ffi::c_int;