C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
_open
 Summary Example                         Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
     The _open function opens the file specified by <filename> and
     prepares the file for subsequent reading or writing, as defined
     by <oflag>. The <oflag> argument is an integer expression formed
     by combining one or more of the following manifest constants
     (defined in FCNTL.H):
 
     _O_APPEND     _O_EXCL       _O_TEXT
     _O_BINARY     _O_RDONLY     _O_TRUNC
     _O_CREAT      _O_RDWR       _O_WRONLY
 
     When more than one manifest constant is given, the constants are
     combined with the bitwise-OR operator (|).
 
     See BINMODE.OBJ for a discussion of binary (_O_BINARY) and text
     (_O_TEXT) modes.
 
     Use the _O_TRUNC flag with care, as it destroys the complete
     contents of an existing file.
 
     Either _O_RDONLY, _O_RDWR, or _O_WRONLY must be given to specify
     the access mode. There is no default value for the access mode.
 
     The <pmode> argument is required only when _O_CREAT is specified.
     If the file exists, <pmode> is ignored. Otherwise, <pmode>
     specifies the file's permission settings, which are set when the
     new file is closed for the first time. The <pmode> argument is an
     integer expression containing one or both of the manifest
     constants _S_IWRITE and _S_IREAD (defined in SYS\STAT.H). When
     both constants are given, they are joined with the bitwise-OR
     operator (|).
 
     If write permission is not given, the file is read-only. With DOS,
     all files are readable; it is not possible to give write-only
     permission. Thus, the modes _S_IWRITE and _S_IREAD | _S_IWRITE are
     equivalent.
 
     The _open function applies the current file-permission mask to
     <pmode> before setting the permissions (see _umask).
 
     The <filename> used in the _open function is affected by the DOS
     APPEND command.
 
     Under DOS versions 3.0 and later with SHARE installed, a problem
     occurs when opening a new file with <oflag> set to _O_CREAT |
     _O_RDONLY or _O_CREAT | _O_WRONLY and <pmode> set to _S_IREAD. In
     this case, the operating system prematurely closes the file during
     system calls made within open.
 
     To get around the problem, open the file with <pmode> set to
     _S_IWRITE. After closing the file, call _chmod and change the mode
     back to _S_IREAD. Another possibility is to open the file with
     <pmode> set to _S_IREAD and <oflag> set to _O_CREAT | _O_RDWR.
 
     Return Value
 
     The _open function returns a file handle for the opened file. A
     return value of -1 indicates an error, and errno is set to EACCES,
     EEXIST, EINVAL, EMFILE, or ENOENT.
                                    -♦-