Syntax
#include <fcntl.h> #include <sys\stat.h> #include <share.h> #include <io.h> int _sopen(char *pathname, int oflag, int shflag, int pmode);Description
Oflag
The shflag argument is one of the following constants, defined in <share.h>: compact break=fit.
Shflag
There is no default value for the shflag.
The pmode argument is required only when you specify O_CREAT. If the file does not exist, pmode specifies the permission settings of the file, which are set when the new file is closed for the first time. If the file exists, the value of pmode is ignored. The pmode must be one of the following values, defined in <sys\stat.h>: compact break=fit.
Value
If write permission is not given, the file is read-only. On the OS/2 operating system, all files are readable; you cannot give write-only permission. Thus, the modes S_IWRITE and S_IREAD | S_IWRITE are equivalent. Specifying a pmode of S_IREAD is similar to making a file read-only with the ATTRIB system command.
_sopen applies the current file permission mask to pmode before setting the permissions. (See umask for information on file permission masks.)
Value
This example opens the file sopen.datforsharedreadingandwritingusing_ sopen .Itthenopensthefileforsharedreading .
#include <io.h>#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <share.h> #define FILENAME "sopen.dat" int main(void) { int fh1,fh2; printf("Creating file.\n"); system("echo Sample Program > " FILENAME); /* share open the file for reading and writing */ if (-1 == (fh1 = _sopen(FILENAME, O_RDWR, SH_DENYNO))) { perror("sopen failed"); remove(FILENAME); return EXIT_FAILURE; } /* share open the file for reading only */ if (-1 == (fh2 = _sopen(FILENAME, O_RDONLY, SH_DENYNO))) { perror("sopen failed"); close(fh1); remove(FILENAME); return EXIT_FAILURE; } printf("File successfully opened for sharing.\n"); close(fh1); close(fh2); remove(FILENAME); return 0; /**************************************************************************** The output should be: Creating file. File successfully opened for sharing. ****************************************************************************/ }Related Information