Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <stdio.h>
    FILE *_fsopen( const char *filename,
                   const char *mode, int share );
    FILE *_wfsopen( const wchar_t *filename,
                    const wchar_t *mode, int share );

Description:
    The _fsopen function opens the file whose name is the string pointed to
    by filename, and associates a stream with it.  The arguments mode and
    share control shared reading or writing.  The argument mode points to a
    string beginning with one of the following sequences:

    Mode     Meaning

"r"
    open file for reading; use default file translation

"w"
    create file for writing, or truncate to zero length; use default file
    translation

"a"
    append:  open text file or create for writing at end-of-file; use
    default file translation

"rb"
    open binary file for reading

"rt"
    open text file for reading

"wb"
    create binary file for writing, or truncate to zero length

"wt"
    create text file for writing, or truncate to zero length

"ab"
    append; open binary file or create for writing at end-of-file

"at"
    append; open text file or create for writing at end-of-file

"r+"
    open file for update (reading and/or writing); use default file
    translation

"w+"
    create file for update, or truncate to zero length; use default file
    translation

"a+"
    append; open file or create for update, writing at end-of-file; use
    default file translation

"r+b", "rb+"
    open binary file for update (reading and/or writing)

"r+t", "rt+"
    open text file for update (reading and/or writing)

"w+b", "wb+"
    create binary file for update, or truncate to zero length

"w+t", "wt+"
    create text file for update, or truncate to zero length

"a+b", "ab+"
    append; open binary file or create for update, writing at end-of-file

"a+t", "at+"
    append; open text file or create for update, writing at end-of-file

    When default file translation is specified, the value of the global
    variable  _fmode establishes whether the file is to treated as a binary
    or a text file.  Unless this value is changed by the program, the
    default will be text mode.

    Opening a file with read mode ('r' as the first character in the mode
    argument) fails if the file does not exist or it cannot be read.
     Opening a file with append mode ('a' as the first character in the mode
    argument) causes all subsequent writes to the file to be forced to the
    current end-of-file, regardless of previous calls to the  fseek
    function.  When a file is opened with update mode ('+' as the second or
    third character of the mode argument), both input and output may be
    performed on the associated stream.

    When a stream is opened in update mode, both reading and writing may be
    performed.  However, writing may not be followed by reading without an
    intervening call to the  fflush function or to a file positioning
    function ( fseek,  fsetpos,  rewind).  Similarly, reading may not be
    followed by writing without an intervening call to a file positioning
    function, unless the read resulted in end-of-file.

    The shared access for the file, share, is established by a combination
    of bits defined in the <share.h> header file.  The following values may
    be set:

    Value     Meaning

SH_COMPAT
    Set compatibility mode.

SH_DENYRW
    Prevent read or write access to the file.

SH_DENYWR
    Prevent write access of the file.

SH_DENYRD
    Prevent read access to the file.

SH_DENYNO
    Permit both read and write access to the file.

    You should consult the technical documentation for the DOS system that
    you are using for more detailed information about these sharing modes.

    The _wfsopen function is identical to _fsopen except that it accepts
    wide-character string arguments for filename and mode.

Returns:
    The _fsopen function returns a pointer to the object controlling the
    stream.  This pointer must be passed as a parameter to subsequent
    functions for performing operations on the file.  If the open operation
    fails, _fsopen returns NULL.  When an error has occurred,  errno
    contains a value indicating the type of error that has been detected.

Example:
    #include <stdio.h>
    #include <share.h>

    void main()
      {
        FILE *fp;

        /*
          open a file and prevent others from writing to it
        */
        fp = _fsopen( "report.dat", "w", SH_DENYWR );
        if( fp != NULL ) {
          /* rest of code goes here */
          fclose( fp );
        }
      }

Classification:
    WATCOM

Systems:
     _fsopen - All, Netware

    _wfsopen - All

See Also:
    fclose, fcloseall, fdopen, fopen, freopen

See Also: fclose fcloseall

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson