#ifndef GIO_H
#define GIO_H
/*----------------------------------------------------------------------*
 * GIO.H  defs for Generic I/O Speed Up Package.             01/06/86
 * See GIOCall.C for an example of usage.
 * Read not speeded-up yet.  Only one Write file buffered at a time.
 * Note: The speed-up provided is ONLY significant for code such as IFF
 * which does numerous small Writes and Seeks.
 *----------------------------------------------------------------------*/
 
/* Use this file interface in place of ALL Open,Close,Read,Write,Seek DOS
 * calls for an optional i/o speed-up via buffering.  You must use ONLY
 * these G routines for a file that is being buffered; e.g., call GClose
 * to Close the file, etc.
 * It is harmless though not necessary to use G routines for a file that
 * is not being buffered; e.g., GClose and Close are equivalent in that
 * case.
 * This Version only buffers one file at a time, and only for writing.
 * If you call GWriteDeclare for a second file before the first file
 * is GClosed, the first file becomes unbuffered.  This is harmless, no
 * data is lost, the first file is simply no longer speeded-up.
 */
 
/* Before compiling any modules that make G calls, or compiling gio.c,
 * you must set the GIO_ACTIVE flag below.
 *
 * To omit the speed-up code,
 *    #define GIO_ACTIVE 0
 *
 * To make the speed-up happen:
 * 1. #define GIO_ACTIVE 1
 * 2. link gio.o into your program
 * 3. GWriteDeclare(file, buffer, size)
 *    after f
GOpening the file and before doing
 *    any writing.
 * 4. ONLY use GRead, GWrite, GSeek, GClose -- do not use the DOS i/o
 *    routines directly.
 */
#define GIO_ACTIVE 1
 
#ifndef EXEC_TYPES_H
#include "exec/types.h"
#endif
 
#ifndef LIBRARIES_DOS_H
#include "libraries/dos.h"
#endif
 
#ifndef OFFSET_BEGINNING
#define OFFSET_BEGINNING OFFSET_BEGINING
#endif
 
#if GIO_ACTIVE
 
/* Present for completeness in the interface.
 * "openmode" is either MODE_OLDFILE to read/write an existing file, or
 * MODE_NEWFILE to write a new file.
 * RETURNs a "file" pointer to a system-supplied structure that describes
 * the open file.  This pointer is passed in to the other routines below.*/
/* extern BPTR GOpen(char *, int openmode); */
 
/* NOTE: Flushes & Frees the write buffer.
 * Returns -1 on error from Write.*/
/* extern int GClose(BPTR file);  */
 
/* Read not speeded-up yet.
 * GOpen the file, then do GReads to get successive chunks of data in
 * the file.  Assumes the system can handle any number of bytes in each
 * call, regardless of any block-structure of the device being read from.
 * When done, GClose to free any system resources associated with an
 * open file.*/
/* extern int GRead(BPTR, BYTE *, int nBytes);  */
 
/* Writes out any data in write buffer for file.
 * NOTE WHEN have Seeked into middle of buffer:
 * GWriteFlush causes current position to be the end of the data written.
 * -1 on error from Write.*/
/* extern int GWriteFlush(BPTR file);  */
 
/* Sets up variables to describe a write buffer for the file.*/
/* -1 on error from Write.*/
/* extern int GWriteDeclare(BPTR, BYTE *, LONG); */
 
/* ANY PROGRAM WHICH USES "GWrite" MUST USE "GSeek" rather than "Seek"
 * TO SEEK ON A FILE BEING WRITTEN WITH "GWrite".
 * "Write" with Generic speed-up.
 * -1 on error from Write.  else returns # bytes written to disk.
 * Call GOpen, then do successive GWrites with GSeeks if required,
 * then GClose when done.  (IFF does require GSeek.)*/
/* extern int GWrite( BPTR, BYTE *, int nBytes); */
 
/* "Seek" with Generic speed-up, for a file being written with GWrite.*/
/* Returns what Seek returns, which appears to be the position BEFORE
 * seeking, though the documentation says it returns the NEW position.*/
/* CURRENTLY RETURNS 0 WHEN SEEKING WITHIN THE BUFFER.*/
/* Eventually, will support two independent files, one being read, the
 * other being written.  Or could support even more.  Designed so is safe
 * to call even for files which aren't being buffered.*/
/* extern int GSeek(BPTR, BYTE *, int mode);     */
 
#else /* not GIO_ACTIVE */
 
#define GOpen(filename, openmode)           Open(filename, openmode)
#define GClose(file)               Close(file)
#define GRead(file, buffer, nBytes)       Read(file, buffer, nBytes)
#define GWriteFlush(file)          (0)
#define GWriteDeclare(file, buffer, nBytes) (0)
#define GWrite(file, buffer, nBytes)       Write(file, buffer, nBytes)
#define GSeek(file, position, mode)       Seek(file, position, mode)
 
#endif GIO_ACTIVE
 
#endif
