Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>fdopen</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
fdopen

Usage

   #include <io.h>
   FILE *fdopen(int fd, char *mode);

Description

   This function allows the buffering of a file which has already been
   opened as an unbuffered file using open(). The handle of the already
   opened file is passed as the first argument and the file mode as the
   second. If the specified mode is an append mode, the file pointer is
   positioned at the end of the file, otherwise the file pointer is
   positioned at the beginning of the file. If the specified mode is a write
   mode, the file is truncated.

   Note-No checking is done to assure that the mode of the buffered file is
   compatible with the rwmode of the unbuffered file. Incompatibility of
   file modes will give undefined results.

Example 

   #include <stdio.h>
   #include <dos.h>
   #include <io.h>
   #include <stdlib.h>

   int main()
   {
       int fd;
       FILE *fp;
       char line[81];

       if ((fd = open("stdio.h", O_RDONLY)) == -1) {
           printf("Can't open stdio.h\n");
           return EXIT_FAILURE;

       }
       if ((fp = fdopen(fd, "r")) == NULL) {
           printf("Can't fdopen stdio.h\n");
           return EXIT_FAILURE;
       }
       fgets(line, 80, fp);
       printf("The first line of stdio.h is:\n%s\n",line);
       return EXIT_SUCCESS;
   }

Return Value

   A FILE pointer to opened file

See Also

   open, fopen



See Also: open fopen

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