Home Web Design Programming Fairlight CMI Soap Box Downloads Links Biography About... Site Map

The Holmes Page Using fopen() To Open files

CA-Clipper Opportunities Tips and Tricks Networking Internal Errors Source Code CA-VO



BACK TO
CA-CLIPPER
NETWORKING

The fopen() function is used to perform what is known as "low-level file handling", which is used when you need to get at data in a non-DBF file. Typical uses would be for reading and writing values in the CONFIG.SYS or AUTOEXEC.BAT files, or in a utility to handle compressed files. 
The two most common open modes used in fopen() are exclusive read-write and shared read-only. The open mode is specified in the second parameter to the function. 
Sharing Access
Bit 7   6  5  4   3   2  1  0 
Value128 643216 8 421
The values of the second parameter to the fopen() function are calculated by adding the bit values according to the table to the left. 
This task is simplified because CA-Clipper comes with a header file, called fileio.ch, which contains these defines:
   // FOPEN() access modes
   #define FO_READ      0     // Open for reading (default)
   #define FO_WRITE     1     // Open for writing
   #define FO_READWRITE 2     // Open for read or write

   // FOPEN() sharing modes (combine with open mode using +)
   #define FO_COMPAT    0     // Compatibility (default)
   #define FO_EXCLUSIVE 16    // Exclusive use
   #define FO_DENYWRITE 32    // Prevent others writing
   #define FO_DENYREAD  48    // Prevent others reading
   #define FO_DENYNONE  64    // Allow others to read/write
   #define FO_SHARED    64    // Same as FO_DENYNONE
To open a file in exclusive read/write mode (for example) you would specify: 
   fopen(file, FO_EXCLUSIVE+FO_READWRITE) 
This would allow your program total access to the file, while preventing others. 
Another common mode is shared read-only, which is the "safest" mode and allows other to access the file at the same time. 
   fopen(file, FO_SHARED+FO_READ)


Home Web Design Programming Fairlight CMI Soap Box Downloads Links Biography About... Site Map

Site Map Send comments about this site to Greg at gregh@ghservices.com
All pages copyright © 1996-1999 GH Services™   Created 1997/06/09   Last updated 1999/09/30
All trademarks contained herein are the property of their respective owners