In the process of C++ project, a function of opening and saving files needs to be implemented. After I write to the file tmp.dat, I want to write to the file for the second time. At this time, an error returning int error = 13 (Permission denied) occurs in both fopen_s and _wfopen_s.
Since the project is Unicode encoded, there is no way to use Fopen for file operations (fopen is available and Shared reads and writes are available as long as _CRT_SECURE_NO_WARNINGS is added to the precompile, which I don’t want to do). So all kinds of search, and look up MSDN. Here’s what it says on MSDN:
Files opened by fopen_s and _wfopen_s are not sharable. If you require that a file be sharable, use _fsopen, _wfsopen with the appropriate sharing mode constant (for example, _SH_DENYNO for read/write sharing).
Link: https://msdn.microsoft.com/zh-cn/library/z5hh6ee9 (v = versus 90). Aspx
That is, fopen_s and _Wfopen_s do not support file sharing. When you use fopen_s or _wfopen_s for read or write operations, you can only do one operation (i.e., you can only do one read or write operation). Note: If you use fopen_s or _wfopen_s once for a file in a different place, the file becomes unshared. If you read or write a file again, you may return an int error = 13 (EACCES (Permission denied). I just changed one place in the project, but it still doesn’t work the second time. I need to change all the places that involve reading and writing to _fsopen, _wfsopen.
FILE * FP = _wfsopen(tmpFile, _T(” WB “), _SH_DENYNO);
Since the project is Unicode encoded, there is no way to use Fopen for file operations (fopen is available and Shared reads and writes are available as long as _CRT_SECURE_NO_WARNINGS is added to the precompile, which I don’t want to do). So all kinds of search, and look up MSDN. Here’s what it says on MSDN:
Files opened by fopen_s and _wfopen_s are not sharable. If you require that a file be sharable, use _fsopen, _wfsopen with the appropriate sharing mode constant (for example, _SH_DENYNO for read/write sharing).
Link: https://msdn.microsoft.com/zh-cn/library/z5hh6ee9 (v = versus 90). Aspx
That is, fopen_s and _Wfopen_s do not support file sharing. When you use fopen_s or _wfopen_s for read or write operations, you can only do one operation (i.e., you can only do one read or write operation). Note: If you use fopen_s or _wfopen_s once for a file in a different place, the file becomes unshared. If you read or write a file again, you may return an int error = 13 (EACCES (Permission denied). I just changed one place in the project, but it still doesn’t work the second time. I need to change all the places that involve reading and writing to _fsopen, _wfsopen.
FILE * FP = _wfsopen(tmpFile, _T(” WB “), _SH_DENYNO);
Read More:
- Solved “openssl config failed: error:02001003:system library:fopen:No such process” for Nodejs Windo
- could not be opened to write the process output: fopen(/tmp\sf_proc_00.out.lock)
- Solution for Error Code: s1023 when installing DirectX SDK
- Error Code: S1023 when installing DirectX SDK
- Error 1051 (42s02): unknown table ‘…’
- K8s configure HTTPS with existing certificate
- Something‘s wrong–perhaps a missing \item. \begin{thebibliography}{1}
- LIBGL error: no matching fbconfigs or visual s found
- mysql ERROR 1050 (42S01): Table already exists
- How to Disassemble/Assemble Galaxy S4 i9500 for Screen/Parts Repair!
- Installation of k8s Helm
- Summary of k8s single master cluster deployment
- Uncaught Error: Bootstrap‘s JavaScript requires jQuery
- S32ds: error in services launch sequence when debugging with JLINK
- MySQL error operation should contain 1 column (s)
- ERROR 11668 — [ restartedMain] o.s.boot.SpringApplication : Application run failed
- K8s error in installing calico plug-in
- How to Solve K8S Error getting node
- SQL Error: 0, SQLState: 08S01 & Communications link failure
- BUG:soft lockup – CPU#0 stuck for 67s! [migration/0:5]