Warning! None of the fields of the structure below can be modified directly
from the user code. If they are modified directly, the behaviour of the library
is undefined.
Unless specified otherwise, read access is of course allowed.
The dynamic memory allocation/releasing is done by the library (assuming that
adfFileOpen() is followed by adfFileClose()).
struct AdfFile {
struct AdfVolume * volume; // pointer to the volume
struct bFileHeaderBlock * fileHdr; // the header block
void * currentData; // current data block
struct bFileExtBlock * currentExt; // current data extension block
unsigned nDataBlock; // number of current data block
SECTNUM curDataPtr; // pointer to the current data block
unsigned long pos; // file pos
int posInDataBlk; // index in a datablock
int posInExtBlk; // index in a file header or file extension block
BOOL eof; // TRUE is the last byte has been read, use adfEndOfFile()
BOOL modeRead, // TRUE if the file is opened in read mode
modeWrite; // TRUE if the file is opened in write mode
BOOL currentDataBlockChanged; // in write mode, set if the datablock currently in memory has changed
};
adfFileOpen()
ADF_FILE_MODE_READADF_FILE_MODE_WRITEADF_FILE_MODE_READ | ADF_FILE_MODE_WRITEADF_FILE_MODE_WRITE then:
adfFileTruncate() must be used for that)Some basic access permissions are just checked for now.
AdfFile structure, which can be used for further file
operations (read/write/truncate).NULL if an error occurs, ie.
adfFlushFile()
adfFileClose()
adfFileRealSize()
The blockSize must be 488 or 512. This information is located in the datablockSize of the Volume structure.
If the pointers dataN and extN aren't NULL, the number of data blocks and file extension blocks are returned.
adfFileRead()
Use adfEndOfFile() to check if the end of the file is reached or not.
#include "adflib.h"
const unsigned BUFSIZE = 600;
unsigned char buf[BUFSIZE];
/* a device and a volume 'vol' has been successfully mounted */
/* opens the Amiga file */
struct AdfFile * const file = adfFileFile(vol, "mod.and.distantcall", ADF_FILE_MORE_READ);
if ( file == NULL ) { /* free resources and exit */ };
/* opens the output classic file */
FILE * const out = fopen("mod.distant","wb");
if ( out == NULL ) { adfCloseFile(file); /* ... */ };
/* copy the Amiga file into the standard file, 600 bytes per 600 bytes */
long n = adfFileRead(file, BUFSIZE, buf);
while ( ! adfEndOfFile(file) ) {
fwrite(buf, sizeof(unsigned char), n, out);
n = adfFileRead(file, BUFSIZE, buf);
}
/* after the EOF is reached, some bytes may need to be written */
if ( n > 0 )
fwrite(buf, sizeof(unsigned char), n, out);
/* closes the standard file */
fclose(out);
/* closes the Amiga file */
adfFileClose(file);
adfEndOfFile()
adfFileWrite()
#include"adflib.h"
const unsigned BUFSIZE = 600;
unsigned char buf[BUFSIZE];
/* a device and a volume 'vol' has been successfully mounted */
struct AdfFile * file = adfFileOpen(vol, "moon_gif", ADF_FILE_MODE_READWRITE);
if ( file == NULL ) { /* error handling */ };
FILE * in = fopen(argv[2], "rb");
if ( out == NULL ) { adfFileClose(file); /* error handling */ };
n = fread(buf, sizeof(unsigned char), BUFSIZE, out);
while ( ! feof(out) ) {
adfFileWrite(file, n, buf);
n = fread(buf, sizeof(unsigned char), BUFSIZE, out);
}
if ( n > 0 )
adfFileWrite(file, n, buf);
fclose(out);
adfFileClose(file);