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.
_sopen
 Summary Example                         Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
     The _sopen function opens the file specified by <filename> and
     prepares the file for subsequent shared reading or writing, as
     defined by <oflag> and <shflag>.
 
     The integer expression <oflag> is formed by combining one or more
     of the following manifest constants (defined in FCNTL.H). (When
     more than one manifest constant is given, the constants are joined
     with the bitwise-OR operator (|).)
 
     _O_APPEND     _O_EXCL       _O_TEXT
     _O_BINARY     _O_RDONLY     _O_TRUNC
     _O_CREAT      _O_RDWR       _O_WRONLY
 
     The <shflag> argument is a constant expression consisting of one
     of the following manifest constants (defined in SHARE.H):
 
     _SH_COMPAT    _SH_DENYRW
     _SH_DENYNO    _SH_DENYWR
     _SH_DENYRD
 
     If SHARE.COM (or SHARE.EXE in some versions of MS-DOS) is not
     installed, MS-DOS ignores the sharing mode. (See your system
     documentation for detailed information about sharing modes.)
 
     The _sopen function should be used only with MS-DOS version 3.0
     and later. Under earlier versions of MS-DOS, the <shflag> argument
     is ignored.
 
     The <pmode> argument is required only when _O_CREAT is specified.
     If the file does not exist, <pmode> specifies the file's
     permission settings, which are set when the new file is closed for
     the first time. Otherwise, the <pmode> argument is ignored. 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 combined
     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.
 
     Note that under MS-DOS versions 3.x with SHARE installed, a
     problem occurs when opening a new file with_ sopen under the
     following sets of conditions:
 
        ■ With <oflag> set to _O_CREAT | _O_RDONLY or _O_CREAT |
          _O_WRONLY, <pmode> set to _S_IREAD, and <shflag> set to
          _SH_COMPAT
 
        ■ With <oflag> set to any combination that includes
          _O_CREATE | _O_RDWR, <pmode> set to _S_IREAD, and <shflag>
          set to anything other than _SH_COMPAT
 
     In either case, the operating system prematurely closes the file
     during system calls made within _sopen, or the system generates a
     sharing violation (INT 24H). To avoid 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 solution is to
     open the file with <pmode> set to _S_IREAD, <oflag> set to
     _O_CREAT | _O_RDWR, and <shflag> set to _SH_COMPAT.
 
     The _sopen function applies the current file-permission mask to
     <pmode> before setting the permissions (see _umask).
 
     Return Value
 
     The _sopen 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.
                                    -♦-