Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>_fsopen() open file as a stream</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _fsopen()               Open File as a Stream

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

  FILE *_fsopen(filename, mode, shflag);
 char *filename;    filename
 char *mode;        r, w, a, r+, w+, a+, t, b
 int shflag;        SH_COMPAT, SH_DENYNO, SH_DENYRD, SH_DENYRW, or SH_DENYWR

    This function opens a file as a stream and sets it up for shared
    reading and writing as indicated by the mode and shflag
    parameters.

    Valid modes are "r" (read), "w" (write), and "a" (append). These
    can be followed by a "+", to allow both read and write operations.

    shflag can be one of the following constants (from SHARE.H):

     SH_COMPAT    SH_DENYNO    SH_DENYRD    SH_DENYRW    SH_DENYWR

    Returns:    A pointer to the stream. A NULL pointer indicates
                failure.

    Notes:      If SHARE.COM is not installed, DOS ignores the sharing
                mode. _fsopen() should be used only in OS/2 and DOS
                versions 3+.

 Portability:   Not supported by the ANSI standard.

   -------------------------------- Example ---------------------------------

        #include <stdio.h>
        #include <conio.h>
        #include <share.h>
        #include <stdlib.h>

        void main()
        {
            FILE *myfile;
            char mypath[_MAX_PATH];

            printf("File name: ");
            gets(mypath);

            printf("Opening file, denying others write access....\n");
            if((myfile = _fsopen(mypath, "r", SH_DENYWR)) == NULL)
                printf("Can't open file.");

            printf("Closing the file.\n");
            fcloseall();
        }


See Also: fclose() fdopen() ferror() fileno() fopen() freopen() open()

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