home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / posix / fcntl / open.txh < prev   
Encoding:
Text File  |  1996-04-26  |  2.2 KB  |  96 lines

  1. @node open, io
  2. @subheading Syntax
  3.  
  4. @example
  5. #include <fcntl.h>
  6. #include <sys/stat.h> /* for mode definitions */
  7.  
  8. int open(const char *file, int mode /*, int permissions */);
  9. @end example
  10.  
  11. @subheading Description
  12.  
  13. This function opens the named @var{file} in the given @var{mode}, which
  14. is any combination of the following:
  15.  
  16. @table @code
  17.  
  18. @item O_RDONLY
  19.  
  20. The file is opened for reading.
  21.  
  22. @item O_WRONLY
  23.  
  24. The file is opened for writing.
  25.  
  26. @item O_RDWR
  27.  
  28. The file is opened for both reading and writing.
  29.  
  30. @item O_CREAT
  31.  
  32. If the file does not exist, it is created. @xref{creat}.
  33.  
  34. @item O_TRUNC
  35.  
  36. If the file does exist, it is truncated to zero bytes.
  37.  
  38. @item O_EXCL
  39.  
  40. If the file exists, and @code{O_CREAT} is also specified, the
  41. @code{open} call will fail. 
  42.  
  43. @item O_APPEND
  44.  
  45. The file pointer is positioned at the end of the file before each write. 
  46.  
  47. @item O_TEXT
  48.  
  49. The file is opened in text mode, meaning that Ctrl-M characters are
  50. stripped on reading and added on writing as needed.  The default mode is
  51. specified by the @code{_fmode} variable @ref{_fmode}. 
  52.  
  53. @item O_BINARY
  54.  
  55. The file is opened in binary mode.
  56.  
  57. When called to open the console in binary mode, @code{open} will disable
  58. the generation of @code{SIGINT} when you press @kbd{Ctrl-C}
  59. (@kbd{Ctrl-Break} will still cause @code{SIGINT}), because many programs
  60. that use binary reads from the console will also want to get the
  61. @samp{^C} characters.  You can use the @code{__djgpp_set_ctrl_c} library
  62. function (@pxref{__djgpp_set_ctrl_c}) if you want @kbd{Ctrl-C} to
  63. generate interrupts while console is read in binary mode.
  64.  
  65. @end table
  66.  
  67. If the file is created by this call, it will be given the read/write
  68. permissions specified by @var{permissions}, which may be any combination
  69. of these values:
  70.  
  71. @table @code
  72.  
  73. @item S_IRUSR
  74.  
  75. The file is readable.  This is always true for MS-DOS
  76.  
  77. @item S_IWUSR
  78.  
  79. The file is writable.
  80.  
  81. @end table
  82.  
  83. Other @code{S_I*} values may be included, but they will be ignored.
  84.  
  85. @subheading Return Value
  86.  
  87. If successful, the file descriptor is returned.  On error, a negative
  88. number is returned and @code{errno} is set to indicate the error. 
  89.  
  90. @subheading Example
  91.  
  92. @example
  93. int q = open("/tmp/foo.dat", O_RDONLY|O_BINARY);
  94. @end example
  95.  
  96.