Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/sopen.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/sopen.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/sopen.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/sopen.html on line 8

sopen()

Open a file for shared access

Synopsis:

#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <share.h>

int sopen( const char* filename,
           int oflag, 
           int share,
           ... );

Arguments:

filename
The path name of the file that you want to open.
oflag
Flags that specify the status and access modes of the file. This argument is a combination of the following bits (defined in <fcntl.h>):
share
The shared access for the file. This is a combination of the following bits (defined in <share.h>):

If you set O_CREAT in oflag, you must also specify the following argument:

mode
An object of type mode_t that specifies the access mode that you want to use for a newly created file. For more information, see Access permissions in the documentation for stat().

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The sopen() function opens a file at the operating system level for shared access. The name of the file to be opened is given by filename.

The file is accessed according to the access mode specified by oflag. You must specify O_CREAT if the file doesn't exist.

The sharing mode of the file is given by the share argument. The optional argument is the file permissions to be used when O_CREAT flag is on in the oflag mode; you must provide this when the file is to be created.

The sopen() function applies the current file permission mask to the specified permissions (see umask()).

Note that

open( path, oflag, ... );

is the same as:

sopen( path, oflag, SH_DENYNO, ... );

Note: The sopen() function ignores advisory locks that you may have set by calling fcntl().

Returns:

A descriptor for the file, or -1 if an error occurs while opening the file (errno is set).

Errors:

EACCES
Search permission is denied on a component of the path prefix, or the file exists and the permissions specified by oflag are denied, or the file doesn't exist and write permission is denied for the parent directory of the file to be created.
EBUSY
Sharing mode (share) was denied due to a conflicting open.
EISDIR
The named file is a directory, and the oflag argument specifies write-only or read/write access.
ELOOP
Too many levels of symbolic links or prefixes.
EMFILE
No more descriptors available (too many open files).
ENOENT
Path or file not found.
ENOSYS
The sopen() function isn't implemented for the filesystem specified in path.

Examples:

#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <share.h>

int main( void )
  {
    int filedes ;

    /* open a file for output                  */
    /* replace existing file if it exists      */

    filedes = sopen( "file",
        O_WRONLY | O_CREAT | O_TRUNC,
        SH_DENYWR,
        S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );

    /* read a file which is assumed to exist   */

    filedes = sopen( "file", O_RDONLY, SH_DENYWR );

    /* append to the end of an existing file   */
    /* write a new file if file doesn't exist */

    filedes = sopen( "file",
        O_WRONLY | O_CREAT | O_APPEND,
        SH_DENYWR,
        S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
    return EXIT_SUCCESS;
  }

Classification:

Unix

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

See also:

chsize(), close(), creat(), dup(), dup2(), eof(), execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), fcntl(), fileno(), fstat(), isatty(), lseek(), open(), read(), stat(), tell(), umask(), write()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/sopen.html on line 357

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/sopen.html on line 357