_FOpen( ) API Library Routine Example
The following example creates a test file. It then opens the file in FO_READONLY mode and attempts to write to it. As a result _FError( ) returns 5 for "Access denied." Next, the example opens the test file in FO_WRITEONLY mode, and attempts to read from it. Again, _FError( ) returns 5.
SET LIBRARY TO FOPEN
#include <pro_ext.h>
void putLong(long n)
{
Value val;
val.ev_type = 'I';
val.ev_long = n;
val.ev_width = 10;
_PutValue(&val);
}
#define BUFFSIZE 256
static char lineBuffer[BUFFSIZE];
FAR Example(ParamBlk FAR *parm)
{
FCHAN fchan;
fchan = _FCreate("temp.tmp", FC_NORMAL);
_FCHSize(fchan, 8192);
_FClose(fchan);
fchan = _FOpen("temp.tmp", FO_READONLY);
_FPuts(fchan, "Hello, world");
_PutStr("\nAttempt to _FPuts() to file _FOpen()d FO_READONLY");
_PutStr("\n_FError() ="); putLong(_FError());
_FClose(fchan);
fchan = _FOpen("temp.tmp", FO_WRITEONLY);
_FGets(fchan, lineBuffer, BUFFSIZE);
_PutStr("\nAttempt to _FGets() from file _FOpen()d FO_WRITEONLY");
_PutStr("\n_FError() ="); putLong(_FError());
_FClose(fchan);
}
FoxInfo myFoxInfo[] = {
{"FOPEN", (FPFI) Example, CALLONLOAD, ""},
};
FoxTable _FoxTable = {
(FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};