_FOpen( ) (Rutina de biblioteca API)

Asigna un canal de Visual FoxPro a un archivo existente.

FCHAN _FOpen(char FAR *filename, int mode)
char FAR *filename;         /* Name of existing file */
int mode;                     /* Mode option. */

Observaciones

Están disponibles las siguientes opciones de mode: FO_READONLY, FO_WRITEONLY y FO_READWRITE. _FOpen( ) abre un archivo con acceso exclusivo. _FOpen( ) devuelve el canal de archivo si logra abrir el archivo o devuelve – 1 si no puede abrir el archivo.

Para obtener más información acerca de cómo crear una biblioteca API e integrarla con Visual FoxPro, vea Acceso a la API de Visual FoxPro.

Ejemplo

El siguiente ejemplo crea un archivo de prueba. A continuación, abre el archivo en modo FO_READONLY e intenta escribir en él. Como resultado, _FError( ) devuelve 5 para "Acceso denegado". Por último, el ejemplo abre el archivo de prueba en modo FO_WRITEONLY e intenta leer en él. De nuevo, _FError( ) devuelve 5.

Código Visual FoxPro

SET LIBRARY TO FOPEN 

Código C

#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
};

Vea también

_FClose( ) (Rutina de biblioteca API) | _FCreate( ) (Rutina de biblioteca API) | _FError( ) (Rutina de biblioteca API) | Acceso a la API de Visual FoxPro