netatalk  4.6.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
hqx.h File Reference

Go to the source code of this file.

Functions

int skip_junk (int line)
 Skip non-BinHex text until encoded data is found.
int hqx_open (char *hqxfile, int flags, struct FHeader *fh, int options)
 Open a BinHex file for reading or writing.
int hqx_close (int keepflag)
 Close the active BinHex file.
const char * hqx_path (void)
ssize_t hqx_read (int fork, char *buffer, size_t length)
 Read decoded data from a BinHex fork.
ssize_t hqx_write (int fork, char *buffer, size_t length)
int hqx_header_read (struct FHeader *fh)
 Read and validate a BinHex header.
int hqx_header_write (struct FHeader *fh)
 Encode and write a BinHex header.
size_t hqx_7tobin (char *outbuf, size_t datalen)
 Decode BinHex text data to binary.
ssize_t hqx7_fill (unsigned char *hqx7_ptr)
 Fill the BinHex text input buffer.

Function Documentation

◆ hqx7_fill()

ssize_t hqx7_fill ( unsigned char * hqx7_ptr)

Fill the BinHex text input buffer.

This is called from skip_junk() and hqx_7tobin(). It reads from the BinHex file into the hqx7 buffer and updates hqx7_first and hqx7_last to delimit valid data.

Parameters
[in]hqx7_ptrpointer within hqx7_buf where reading should start
Returns
number of bytes read, 0 on end of file, -1 on error

◆ hqx_7tobin()

size_t hqx_7tobin ( char * outbuf,
size_t datalen )

Decode BinHex text data to binary.

This is called by hqx_header_read() for header data and by hqx_read() for fork data and CRC fields. It buffers decoded data so callers get the requested length unless end of file is reached.

Parameters
[out]outbufdestination buffer for decoded bytes
[in]datalennumber of decoded bytes requested
Returns
number of decoded bytes written to outbuf

◆ hqx_close()

int hqx_close ( int keepflag)

Close the active BinHex file.

This must be called before opening another file with hqx_open(). In write mode, KEEP finishes any remaining fork data, flushes the encoder, and writes the BinHex terminator. TRASH closes the output and removes the incomplete file.

Parameters
[in]keepflagKEEP to keep the output, TRASH to discard it
Returns
0 on success, -1 on error

◆ hqx_header_read()

int hqx_header_read ( struct FHeader * fh)

Read and validate a BinHex header.

This is called by hqx_open() before any fork data is read. It decodes the header fields, initializes fork lengths and CRC state, and verifies the header CRC.

Parameters
[out]fhfile header to populate
Returns
0 on success, negative value on error

◆ hqx_header_write()

int hqx_header_write ( struct FHeader * fh)

Encode and write a BinHex header.

Parameters
[in]fhfile header to write
Returns
0 on success, -1 on error

◆ hqx_open()

int hqx_open ( char * hqxfile,
int flags,
struct FHeader * fh,
int options )

Open a BinHex file for reading or writing.

This must be called before other hqx operations. When opening for reading, it skips the preamble and reads the BinHex header. When opening for writing, it initializes output state and writes the BinHex preamble and header.

Parameters
[in]hqxfileinput file path, or - for standard input
[in]flagsopen flags; O_RDONLY selects read mode
[in,out]fhfile header to read or write
[in]optionsoutput options, such as OPTION_STDOUT
Returns
0 on success, -1 on error

◆ hqx_path()

const char * hqx_path ( void )

◆ hqx_read()

ssize_t hqx_read ( int fork,
char * buffer,
size_t length )

Read decoded data from a BinHex fork.

Call this until it returns zero for each fork. When no fork data remains, the stored fork CRC is read and compared with the calculated CRC before returning zero.

Note
hqx_read() must be called enough times to return zero, and no more than that, for each fork.
Parameters
[in]forkfork selector, DATA or RESOURCE
[out]bufferdestination buffer
[in]lengthmaximum number of bytes to read
Returns
number of bytes read, 0 when the fork is complete, -1 on error

◆ hqx_write()

ssize_t hqx_write ( int fork,
char * buffer,
size_t length )

◆ skip_junk()

int skip_junk ( int line)

Skip non-BinHex text until encoded data is found.

This is called from hqx_open() to find the first valid BinHex line, and from hqx_7tobin() to find subsequent encoded lines.

Parameters
[in]lineFIRST for the first encoded line, OTHER thereafter
Returns
0 on success, -1 if valid encoded data is not found