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

Go to the source code of this file.

Functions

int bin_open (char *binfile, int flags, struct FHeader *fh, int options)
 Open a MacBinary file for reading or writing.
int bin_close (int keepflag)
 Close the active MacBinary file.
const char * bin_path (void)
ssize_t bin_read (int fork, char *buffer, size_t length)
 Read data from a MacBinary fork.
ssize_t bin_write (int fork, char *buffer, size_t length)
 Write data to a MacBinary fork.
int bin_header_read (struct FHeader *fh, int revision)
 Read a MacBinary header into a file header.
int bin_header_write (struct FHeader *fh)
 Write a file header as a MacBinary header.
int test_header (void)
 Test the input header for a supported MacBinary revision.

Function Documentation

◆ bin_close()

int bin_close ( int keepflag)

Close the active MacBinary file.

This must be called before opening another file with bin_open(). KEEP closes the file and preserves it. TRASH closes the file and removes incomplete output.

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

◆ bin_header_read()

int bin_header_read ( struct FHeader * fh,
int revision )

Read a MacBinary header into a file header.

This is called by bin_open() before any fork data is read. It validates the MacBinary revision, decodes header fields, and initializes fork lengths.

Parameters
[out]fhfile header to populate
[in]revisionMacBinary revision returned by test_header()
Returns
0 on success, -1 on error

◆ bin_header_write()

int bin_header_write ( struct FHeader * fh)

Write a file header as a MacBinary header.

This is called by bin_open() before any fork data is written. It encodes the file header as a MacBinary III header and initializes fork lengths.

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

◆ bin_open()

int bin_open ( char * binfile,
int flags,
struct FHeader * fh,
int options )

Open a MacBinary file for reading or writing.

This must be called before other MacBinary operations. When opening for reading, it validates and reads the MacBinary header. When opening for writing, it initializes output state and writes the header.

Parameters
[in]binfileinput 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

◆ bin_path()

const char * bin_path ( void )

◆ bin_read()

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

Read data from a MacBinary fork.

Call this until it returns zero for each fork. When the data fork is complete, it skips MacBinary padding before the resource fork begins.

Note
bin_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

◆ bin_write()

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

Write data to a MacBinary fork.

Data must be written in fork order. The resource fork cannot be written until the data fork is complete. Padding is written when each fork is finished.

Parameters
[in]forkfork selector, DATA or RESOURCE
[in]buffersource buffer
[in]lengthnumber of bytes to write
Returns
number of bytes written, -1 on error

◆ test_header()

int test_header ( void )

Test the input header for a supported MacBinary revision.

Reads the first 128 bytes and determines whether the file is MacBinary, MacBinary II, MacBinary III, or not a MacBinary file.

Note
Apple's MacBinary II files can have a non-zero value at byte 74, so the byte 74 check is not very useful.
Returns
1 for MacBinary, 2 for MacBinary II, 3 for MacBinary III, -1 if the header is invalid