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

Usage

   #include <io.h>
   int dos_open(char *pathname,int rwmode);

Description


   Opens the file specified by pathname. rwmode selects the mode in which
   the  file is opened. The values for rwmode are to be found in dos.h and
   are:

       O_RDONLY    read
       O_WRONLY    write

   This function is implemented as a direct hook to DOS. Other values can be
   passed to DOS (see your DOS manual for more information) but values
   which are undefined to DOS should never be passed via dos_open.

Example 

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

   int main()

   {
       char *fname;
       unsigned int mode;
       int fd;
       mode = O_RDONLY;
       fname = "file.dat";
       fd = dos_open(fname,mode,0);
       if(fd == -1)
           perror("Error opening file");
       else
           {
               printf("\nfile: %s opened for reading\n"
           ,fname);
           close(fd);
           }
       mode = O_WRONLY;
       fname = "CON";
       fd = dos_open(fname,mode,0);
       if(fd < 0)
           printf("\nError opening console for write:%s\n",

       fname);
       else
           {
               printf("\nfile: %s opened for write\n",fname);
               close(fd);
           }
       mode = O_WRONLY | O_CREAT;
       fname = "file.dat";
       fd = dos_open(fname,mode);
       if(fd == -1) {
           perror("Error opening file");
           return EXIT_FAILURE;
       } else
           {
               printf("\nfile: %s opened for output\n"
           ,fname);
               close(fd);
           }
       return EXIT_SUCCESS;
   }


Return Value

   Returns the file descriptor (fd) if successful, -1 if an error occurred.
   errno  is set upon error.

See Also

   close, creat, dos_creat, fopen, open



See Also: dos_creat close creat fopen open

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