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>fdopen() open a stream using a handle</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fdopen()                Open a Stream Using a Handle

 #include   <stdio.h>

 FILE       *fdopen(handle,type);        Pointer to open stream
 int        handle;                      Handle referring to open file
 char       *type;                       Type of access permitted

    fdopen() associates a stream with a file 'handle' obtained from
    creat(), open(), dup(), or dup2().  This enables buffering and
    formatting of a file previously opened for low-level input and
    output.  'type' specifies the type of access requested for the file;
    it must match the access mode with which the file was opened:

        "r"     Read access; the file must already exist.

        "w"     Write access.  Creates a new file for writing or opens an
                existing file for writing.  If the file already exists,
                its contents will be destroyed, so use with caution.

        "a"     Append.  Opens a file for writing at the end-of-file or
                creates a file for writing if the file doesn't exist.
                Existing data cannot be overwritten in this mode.

        "r+"    Update. Opens an existing file for reading and writing;
                the file must exist.

        "w+"    Read and write access.  Opens an empty file for reading
                and writing. If the file exists, its contents will be
                destroyed, so use with caution.

        "a+"    Read and append.  Opens a file for reading and appending.
                If the file doesn't exist, it is created.  All write
                operations take place at the end of the file; existing
                data cannot be overwritten.

    To specify translation mode for new lines, append either of the
    following characters to 'type':

        t       text, or translated mode: CR-LF pairs are translated into
                LF on input; LF is translated to CR-LF on output.

        b       binary, or untranslated mode; translation of CR-LF to LF
                and LF to CR-LF is suppressed.

    If 't' or 'b' is not specified, the default mode variable '_fmode'
    defines the translation mode.  '_fmode' can be set to O_BINARY,
    binary mode, or O_TEXT, text mode.  These constants are defined in
    <fcntl.h>.

    Returns:    A pointer to the open stream; NULL is returned on error.

      Notes:    Both reading and writing are allowed when using "r+",
                "w+" or "a+".  However, you must have an intervening
                fseek or rewind operation when switching between reading
                and writing (or vice versa).

 Portability:   Not supported by ANSI standard.

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

    This example opens a file in read only mode, then associates a stream
    with the open file handle:

           #include <stdio.h>
           #include <fcntl.h>

           FILE *stream;
           int fhndl;

           main()
           {
               fhndl = open("input.txt",O_RDONLY);
               .
               .
               .
               stream = fdopen(fhndl,"r");
           }


See Also: fclose() fcloseall() fopen() freopen() open()

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