libghostty
Loading...
Searching...
No Matches
I/O

Detailed Description

Synchronous callback interfaces used by APIs that consume or produce byte streams. The callback and userdata pointers must remain valid for the full lifetime documented by the API receiving a GhosttyReader or GhosttyWriter.

Typedefs

typedef bool(* GhosttyReaderFn) (void *userdata, uint8_t *buffer, size_t capacity, size_t *out_read)
typedef bool(* GhosttyWriterFn) (void *userdata, const uint8_t *data, size_t len)

Data Structures

struct  GhosttyReader
struct  GhosttyWriter

Typedef Documentation

◆ GhosttyReaderFn

typedef bool(* GhosttyReaderFn) (void *userdata, uint8_t *buffer, size_t capacity, size_t *out_read)

Read bytes from a source.

The callback must set out_read to a value no greater than capacity when returning true. A positive value reports progress; it may be less than capacity and does not indicate end-of-file. A zero value is definitive end-of-file. It must not be used to report temporary input starvation or a would-block condition.

Returning false reports a fatal read error and the value of out_read is ignored. The library does not inspect or modify errno.

All pointer arguments are borrowed and valid only for the duration of the callback. The callback is invoked synchronously on the calling thread.

Parameters
userdataOpaque userdata from GhosttyReader
bufferDestination for read bytes; always non-NULL
capacityWritable capacity of buffer; always greater than zero
[out]out_readNumber of bytes read when returning true; non-NULL
Returns
true for a successful read or end-of-file, false for a fatal error

Definition at line 48 of file io.h.

◆ GhosttyWriterFn

typedef bool(* GhosttyWriterFn) (void *userdata, const uint8_t *data, size_t len)

Write bytes to a destination.

Returning true means all len bytes were accepted. Returning false reports a fatal write error. A callback wrapping an interface that permits partial writes must retry internally until the full slice is accepted or an error occurs.

On failure, the destination may already contain a prefix of the bytes. The calling operation fails and must not be resumed from that partial output. The library does not inspect or modify errno.

data is borrowed and valid only for the duration of the callback. The callback is invoked synchronously on the calling thread. Successful return means the bytes were handed to the destination; it does not imply that the destination was flushed or made durable.

Parameters
userdataOpaque userdata from GhosttyWriter
dataSource bytes; always non-NULL
lenNumber of source bytes; always greater than zero
Returns
true if the complete slice was accepted, false on fatal error

Definition at line 76 of file io.h.