|
Hi Developers,
I have read about sopen() function to open a file in shared mode. Here is the code.
#include <stdio.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <io.h>
#include <share.h>
void main(void);
void main(void)
{
int file_handle;
/* Note that sopen() is not ANSI compliant */
file_handle = sopen"D:\\Study\\file.txt", O_RDWR, SH_DENYNO);
close(file_handle);
}
I am getting "-1" on file_handle and program is also getting crash.
Can u please help me out.
|
|
|
|
|
Check the documentation.
A hint: You need to check errno to get the reason for the failure. Compare that result to the items in errno.h (ex. EACCES, EEXIST, etc..).
|
|
|
|
|
Hi,
This is possible, when the file mentioned is not present in the corresponding path or the file name is wrong you get the file handle as -1.
And its crashing because, you are trying to close a invalid file handle in close() api.
|
|
|
|