[Contents] [Index] [Help] [Retrace] [Browse <] [Browse >]

Writing the IFF chunk data is done with either the WriteChunkBytes() or
WriteChunkRecords() functions.

    error = WriteChunkBytes (iff, buf, size);
    error = WriteChunkRecords (iff, buf, recsize, numrec);

If you specified a valid chunk size when you called PushChunk(),
WriteChunkBytes() and WriteChunkRecords() will truncate attempts to write
past the end of the chunk.

Code to write an ILBM file might take the following form:

    iff = AllocIFF ();
    iff->iff_Stream = Open ("foo", MODE_NEWFILE);
    InitIFFasDOS (iff);
    OpenIFF (iff, IFFF_WRITE);

    PushChunk (iff, ID_ILBM, ID_FORM, IFFSIZE_UNKNOWN);

    PushChunk (iff, ID_ILBM, ID_BMHD, sizeof (struct BitMapHeader));
    WriteChunkBytes (iff, &bmhd, sizeof (bmhd));
    PopChunk (iff);

    PushChunk (iff, ID_ILBM, ID_CMAP, cmapsize);
    WriteChunkBytes (iff, cmapdata, cmapsize);
    PopChunk (iff);

    PushChunk (iff, ID_ILBM, ID_BODY, IFFSIZE_UNKNOWN);
    packwritebody (iff);
    PopChunk (iff);

    PopChunk (iff);

    CloseIFF (iff);
    Close (iff->iff_Stream);
    FreeIFF (iff);

Again, error checking is not present for clarity. See the example code
ClipFTXT.c which writes a simple FTXT clip to the clipboard.