Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- libc - <b>open</b> http://www.ousob.com [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
open
====

Syntax
------

     #include <fcntl.h>
     #include <sys/stat.h> /* for mode definitions */
     
     int open(const char *file, int mode /*, int permissions */);

Description
-----------

This function opens the named FILE in the given MODE, which is any
combination of the following:

`O_RDONLY'
     The file is opened for reading.

`O_WRONLY'
     The file is opened for writing.

`O_RDWR'
     The file is opened for both reading and writing.

`O_CREAT'
     If the file does not exist, it is created. creat:.   

`O_TRUNC'
     If the file does exist, it is truncated to zero bytes.

`O_EXCL'
     If the file exists, and `O_CREAT' is also specified, the `open'
     call will fail.

`O_APPEND'
     The file pointer is positioned at the end of the file before each
     write.

`O_TEXT'
     The file is opened in text mode, meaning that Ctrl-M characters are
     stripped on reading and added on writing as needed.  The default
     mode is specified by the `_fmode' variable _fmode:.   

`O_BINARY'
     The file is opened in binary mode.

     When called to open the console in binary mode, `open' will disable
     the generation of `SIGINT' when you press `Ctrl-C' (`Ctrl-Break'
     will still cause `SIGINT'), because many programs that use binary
     reads from the console will also want to get the `.characters.
     You can use the `__djgpp_set_ctrl_c' library function (*note
     __djgpp_set_ctrl_c::.) if you want `Ctrl-C' to generate interrupts
     while console is read in binary mode.

If the file is created by this call, it will be given the read/write
permissions specified by PERMISSIONS, which may be any combination of
these values:

`S_IRUSR'
     The file is readable.  This is always true for MS-DOS

`S_IWUSR'
     The file is writable.

Other `S_I*' values may be included, but they will be ignored.

Return Value
------------

If successful, the file descriptor is returned.  On error, a negative
number is returned and `errno' is set to indicate the error.

Example
-------

     int q = open("/tmp/foo.dat", O_RDONLY|O_BINARY);


See Also: creat _fmode

Online resources provided by: http://www.ousob.com --- NG 2 HTML conversion by Dave Pearson