Borland C++ reference

_fsopen

raw OCR

Opens a stream with file sharing.

Defined in header <stdio.h>

Syntax

#include <stdio.h>
#include <share.h>
FILE  *fsopenCconst char *filename, const char *mode, int shflg);

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

_fsopen opens the file named by filename and associates a stream with it. _fsopen returns a pointer to be used to identify the stream in subsequent operations.

The mode string used in calls to _fsopen is one of the following values:

Mode Description

Open for reading only. Create for writing. If a file by that name already exists, it will be overwritten. Append; open for writing at end of file, or create for writing if the file does not exist.

r+Open an existing file for update (reading and writing).
10+Create a new file for update (reading and writing). If a file by that name already exists, it will be overwritten.
a+Open for append; open for update at the end of the file, or create if the file does not exist.

To specify that a given file is being opened or created in text mode, append a f to the mode string {rt, iv+t, and so on). Similarly, to specify binary mode, append abto the mode string (wb, a+b, and so on). _fsopen also allows the f or t" to be inserted between the letter and the + character in the mode string; for example, rt+ is equivalent to r+t.

If a f or b is not given in the mode string, the mode is governed by the

global variable _fmode. If Jrnode is set to O_BINARY,files are opened in

binary mode. If _fmode is set to O_TEXT, they are opened in text mode. These O_... constants are defined in fcntl.h.

When a file is opened for update, both input and output can be done on the resulting stream. However, output cannot be followed directly by input without an intervening (seek or rewind, and input cannot be directly followed by output without an intervening fseek, rewind, or an input that encounters end-of-file.

shflag specifies the type of file-sharing allowed on the file filename. The

file-sharing flags are ignored if the DOS SHARE commandhas not been

run. Symbolic constants for shflag are defined in share.h.

Value of shflagWhat it does
SH_COMPATSets compatibility mode
SH_DENYRWDenies read/write access
SH_DENYWRDenies write access
SH_DENYRDDenies read access
SH_DENYNONEPermits read/write access
SH DENYNOPermits read/write access

Return value

On successful completion, _fsopen returns a pointer to the newly opened stream. In the event of error, it returns null.

See also

Example

#include <io.h>
#include <process.h>
#include <share.h>
#include <stdio.h>

int main (void)
{
   FILE *f;
   int status;
   f = _fsopen("c:\\test.$$$",       SH DENYNO)
   if  (f == NULL) {
     printf( "_fsopen failed\n"i
     exit(l);

   status = access ("c:\\test.$$$", 6);
   if (status ==  0)
     printf( "read/write access allowed\n");
   else
     printf( "read/write access not allowed\n");
   fclose (f);
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.