Chapter 13:
Platform-Independent File I/O
 

IOclose(); Platform-independent file close

 

IOconnect(); Platform-independent file connect

 

IOgetc(); Platform-independent file get character

 

IOgets(); Platform-independent file string

 

IOopen(); Platform-independent file open

 

IOread(); Platform-independent file read

 

IOseek(); Platform-independent file seek

 

IOwrite(); Platform-independent file write

   

Ioclose()

 

This function closes the file defined at iopath. It must be a file that was previously opened by IOopen(). This is a platform-independent file close function that can be used in conjunction with IOopen() regardless of the application platform.

Syntax:

INT16 PUBLIC Ioclose (
     IOPATHPTR iopath
);

Input:

iopath: Pointer to an IOPATH data structure that defines the file to be closed. See the IOPATH data structure in Appendix A.

Return:

INT16:

 

Value

Description

 

E00_OK =

file successfully closed

 

E00_FILE_CLOSE_ERROR=

error

Notes:

If this function is used to close a RAM file, your application must also use FreeRamFile() to release the memory used by the RAM file.

Also See:

IOopen()

IOconnect()

 

This function initializes a previously created (IOopen()-ed) IOPATH data structure (at iopath) and sets the cookie entry in the data structure to the cookie value supplied in the input parameter. It connects the platform dependent cookie with the platform-independent iopath.

Syntax:

INT16 PUBLIC
IOconnect (
     IOPATHPTR iopath,
     COOKIE cookie
);

Input:

iopath: Pointer to an IOPATH data structure. See the IOPATH data structure in Appendix A.

 

cookie: For Macintosh applications, this is a typedef short value that identifies a file reference number (refNum). For windows application, this is an INT16 value identifying a DOS file handle. For MSDOS applications, this is a pointer to a "C" file stream.

Return:

Zero

Also See:

IOopen()

   

IOgetc()

 

This is a platform-independent get character (getc()) function. It returns the next character from the file at iopath.

Syntax:

INT16 PUBLIC
IOgetc (
     IOPATHPTR iopath
);

Input:

iopath: Pointer to an IOPATH data structure. See the IOPATH data structure in Appendix A.

Return:

INT16

 

Value

Description

 

Non-Zero =

next character from the file

 

EOF =

End-of-File

Example:

c = IOgetc ( pImport->iop );
lBytesRead++

Also See:

IOopen()

Iogets()

 

This is a platform-independent get string (gets) function. It gets bufsiz characters from the IOopen-ed file (defined at iopath) and stores them at buffer.

Syntax:

LPSTR PUBLIC
Iogets (
     IOPATHPTR iopath,
     char FAR * buffer,
     INT32 bufsiz
);

Input:

iopath: Pointer to an IOPATH data structure. See the IOPATH data structure in Appendix A.

 

buffer: Place to store string

 

bufsiz: Number of characters to get

Return:

LPSTR

 

Value

Description

 

NULL =

EOF

 

Non-Zero =

bufsiz characters successfully read and stored

Example:

char st64 [64] ; /* place to store string */
IOgets ( iop, st64, 64 );

Also See:

IOopen()

Ioopen()

 

This function is a platform-independent file open function. It can be used to open a RAM file or a disk file regardless of the application platform. The file can be opened for read/write or read only access.

Syntax:

INT16
Ioopen (
     IOPATHPTR iopath,
     char FAR * fileName,
     INT16 vRefNum,
     BOOLEAN16 rw
);

Input:

iopath: Pointer to an IOPATH data structure. See the IOPATH data structure in Appendix A.

 

fileName: A string of characters identifying the file name to be opened

 

vRefNum: For Macintosh applications only, INT16 volume reference number

 

rw: Read/Write Flag:

 

#define

Value

Description

 

IO_RD_WR =

TRUE

read/write

 

IO_RD_ONLY=

FALSE

read only

Return:

INT16

 

Value

Description

 

Zero =

no errors/file opened successfully

 

Non-Zero =

error/file not opened

Example:

/* Open the file for writing */
nErr = IOopen(&iop, szFile, 0, IO_RD_WR);
if (nErr)
{
     sprintf(szTemp,
     "IOopen for '%s' failed(%d)!",
     szFile, nErr);
     MessageBox(hWnd,szTemp,"MDEBUG_RAMFILE",
     MB_OK | MB_ICONHAND | MB_TASKMODAL );
     goto all_done;
}
all_done:/* CLOSE THE FILE HANDLE */
IOclose(&iop);

Also See:

IOread(), IOseek(), IOwrite(), IOclose()

Ioread()

 

This function reads binary data from a file previously opened by IOopen(). It is a platform-independent file read function that can be used regardless of the application platform.

Syntax:

INT32 PUBLIC
Ioread (
     IOPATHPTR iopath,
     void FAR * buffer,
     INT32 bufsiz
);

Input:

iopath: Pointer to an IOPATH data structure previously initialized by IOopen(). See the IOPATH data structure in Appendix A.

 

buffer: Point to a location to store read characters

 

bufsiz: Number of bytes to read from file

Return:

INT32: number of bytes actually read

Example:

bCount=IOread(iopath,
     (char FAR *)pB,
     (INT32)sizeof( pB ) );

Also See:

IOopen(), IOseek(), IOwrite()

   

IOseek()

 

This function seeks past lBytes in a file starting at nOrigin.

Syntax:

INT32 PUBLIC
IOseek (
     IOPATHPTR ioPath,
     long lBytes,
     INT16 nOrigin
);

Input:

iopath: Pointer to an IOPATH data structure. See the IOPATH data structure in Appendix A.

 

lBytes: Value specifying the number of bytes to seek/skip past nOrigin

 

nOrigin:

 

#define

#if defined
(applec) ||
defined
(THINK_C)

#elif defined
(WIN32) ||
defined
(MSDOS)

Description

 

IO_SEEK_BEG =

0x0001

0x0000

seek from beginning of the file

 

IO_SEEK_CUR =

0x0003

0x0001

seek from current position.

 

IO_SEEK_END =

0x0002

0x0002

seek from end of the file.

Return:

INT32 value identifying the new location in the file

Example:

/* Get length of ramfile
by seeking to end of file.*/
lBytes = IOseek ( &iop, 0L, IO_SEEK_END );

Also See:

IOopen()

Iowrite()

 

This is a platform-independent file write function that writes bufsiz bytes from the buffer at buffer to the file identified by iopath. The file must have been previously opened in read/write mode (IO_RD_WR) by IOopen().

Syntax:

INT32 PUBLIC
Iowrite (
     IOPATHPTR iopath,
     void FAR * buffer,
     INT32 bufsiz
);

Input:

iopath: Pointer to an IOPATH data structure previously created/initialized by IOopen(). See the IOPATH data structure in Appendix A.

 

buffer: Pointer to a buffer of information to write in the file

 

bufsiz: Number of bytes to write.

Return:

INT32: Number of bytes actually written in the file

Example:

if (lBytes != IOwrite(&iop, pData, lBytes))
{
     wsprintf(szTemp,
     "IOwrite failed (Only wrote %d bytes)!",
     lBytes);
}

Also See:

IOopen(), IOread()