sopen
Opens a file or stream for shared access
#include <nwfileio.h>
int sopen (
const char *path,
int oflag,
int shflag,
...);
When an error occurs while opening the file, a value of –1 is returned. Otherwise, an integer (not equal to –1), known as the file handle, is returned to be used with the other functions that operate on the file.
When an error occurs, errno is set to:
|
Decimal |
Constant |
Description |
|---|---|---|
|
1 |
ENOENT |
No such file. |
|
6 |
EACCESS |
Permission denied. |
|
9 |
EINVAL |
Invalid argument. |
When an error occurs, NetWareErrno is set to:
|
Decimal |
Hex |
Constant |
|---|---|---|
|
107 |
(0x6B) |
ERR_BAD_SHFLAG |
|
108 |
(0x6C) |
ERR_BAD_ACCESS |
|
152 |
(0x98) |
ERR_INVALID_VOLUME |
|
156 |
(0x9C) |
ERR_INVALID_PATH |
NOTE:A problem was introduced in the 4.01d version of clib.nlm. It manifests itself when sopen is called multiple times by the same thread.
In clib.nlm versions prior to 4.01d, a valid file handle will be returned from sopen when a file is opened multiple times by the same thread. In the 4.01d version of clib.nlm (and later versions) an error occurs and returns -1 while errno is set to EINUSE.
Beginning with version 4.10d (notice this is 4.1 and not 4.01) PTR 2/1/95, you can pass the NWSH_PRE_401D_COMPAT bit (0x80000000) in as part of the share flags passed to sopen to get functionality of clib versions prior to 4.01d (if you have experienced problems with multiple threads opening the same file multiple times).
As an alternative to the above work around, you can pass in a CLIB_OPT switch on the command line of the .nlm you are using. CLIB_OPT/U86414 will provide the same functionality as passing in the share flags with the additional bits ORed in. This is only available on clib.nlm version 4.10d PTF.
This function also works on the DOS partition.
The path of the file to be opened is given by the path parameter. The file is accessed according to the access mode specified by the oflag parameter.
The access mode is established as a combination of the bits defined in the FCNTL.H header file. The following bits can be set:
O_CREAT must be specified when the file does not exist and it is to be written.
The shared access for the file is established by the combination of bits set in the shflag parameter where the following values are defined in NWFATTR.H.
NOTE:If a new file is created by this function, the share flag is ignored.
An optional fourth parameter, int permission, is used when the file is to be created (O_CREAT is specified) to set file permissions. File permissions are set according to the value contained in the permission parameter. The access permissions for the file is specified as a combination of bits (defined in the SYS\STAT.H header file).
The permission parameter can be specified as S_IWRITE, S_IREAD or S_IWRITE|S_IREAD. Specifying 0 also makes a file both writable and readable.
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <nwbindry.h>
#include <nwfattr.h>
#include <nwerrno.h>
#include <nwconn.h>
#include <nwfileio.h>
#include <unistd.h>
#define BUFFER_SIZE 512
main()
{
int ccode, handle;
errno=0;
printf("Login %s\r\n\n", LoginToFileServer("ADMIN",//
supervisor for NW 3.x OT_USER,"\x0")?"Failed":"Succeeded");
handle=sopen("test.c", O_RDWR, SH_DENYNO, 0);
if (handle==-1)
{
printf("\r%s\r\n\n",strerror(errno));
close(handle);
Logout();
exit(0);
}
ccode=lock(handle, 1, 10);
if (ccode)
{
printf("\n***lock failed\n");
printf("r%s\r\n\n", strerror(errno));
}
else
printf("\n***lock succeeded\n");
getch();
ccode=unlock(handle, 1, 10);
if (ccode)
{
printf("\n***unlock failed\n");
printf("\r%s\r\n\n", strerror(errno));
}
else
printf("\n***unlock succeeded\n");
close(handle);
Logout();
}