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>open</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
open

Usage

   #include <io.h>
   int open(char *file,int oflag[,int pmode]);

Description

   This function opens a file for reading, writing or appending to. The
   function arguments are:


   int fd           Handle of opened file or ERROR

   char *file       Name of file to open

   int oflag        Operations allowed - one or more of:


                    O_APPEND         position file pointer to end

                    O_CREAT          create file if it does not exist

                    O_EXCL           used with O_CREAT, returns an error if
                                     file            already exists

                    O_RDONLY         open file for reading only

                    O_RDWR           open file for reading and writing

                    O_TRUNC          truncates an existing file

                    O_WRONLY         opens file for writing only


   int pmode       Optional permission mode - one or more of:

                    S_IWRITE         used with O_CREAT, permit writing


                    S_IREAD          used with O_CREAT, permit reading



Example 

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

   int main()
   {
       int fd;
       if (ERROR == (fd = open("file.ext",O_CREAT | O_RDWR,
           S_IWRITE))) {
           printf ("Can't open file.ext");
           return EXIT_FAILURE;
       }
       return EXIT_SUCCESS;

   }

Return Value

   A file handle to the opened file, else -1 and errno is set.

See Also

   sopen



See Also: sopen

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