mirror of
https://github.com/curl/curl.git
synced 2026-07-26 07:17:16 +03:00
curlx/fopen: replace open CRT functions their with _s counterparts (Windows)
- `_wopen` -> `_wsopen_s` - `_open`, `open` -> `_sopen_s` - `_wfopen` -> `_wfopen_s` - `fopen` -> `fopen_s` - `_wfreopen` -> `_wfreopen_s` - `freopen` -> `freopen_s` For better error handling and for using the CRT functions recommended via warnings suppressed by `_CRT_SECURE_NO_WARNINGS`. Also: - add missing `freopen_s()` prototype when building with mingw-w64 <5. https://sourceforge.net/p/mingw-w64/mingw-w64/ci/a5d824654cdc57f6eac1bb581b078986f3eb6856/ - tests/server: replace `open()` in the signal handler with `_sopen_s()` on Windows. - tests/server: reduce scope of a checksrc exception to a single line. - checksrc: ban replaced functions. Refs: https://learn.microsoft.com/cpp/c-runtime-library/reference/open-wopen https://learn.microsoft.com/cpp/c-runtime-library/reference/sopen-s-wsopen-s https://learn.microsoft.com/cpp/c-runtime-library/reference/freopen-wfreopen https://learn.microsoft.com/cpp/c-runtime-library/reference/fopen-wfopen https://learn.microsoft.com/cpp/c-runtime-library/reference/fopen-s-wfopen-s https://learn.microsoft.com/cpp/c-runtime-library/reference/freopen-s-wfreopen-s Closes #19643
This commit is contained in:
parent
ee97c2a96a
commit
1e7d0bafc6
5 changed files with 31 additions and 16 deletions
|
|
@ -6,7 +6,6 @@ allowfunc accept
|
|||
allowfunc fprintf
|
||||
allowfunc freeaddrinfo
|
||||
allowfunc getaddrinfo
|
||||
allowfunc open
|
||||
allowfunc printf
|
||||
allowfunc recv
|
||||
allowfunc send
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@
|
|||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <share.h>
|
||||
#endif
|
||||
|
||||
/* This function returns a pointer to STATIC memory. It converts the given
|
||||
* binary lump to a hex formatted string usable for output in logs or
|
||||
* whatever.
|
||||
|
|
@ -359,13 +363,17 @@ static void exit_signal_handler(int signum)
|
|||
(void)!write(STDERR_FILENO, msg, sizeof(msg) - 1);
|
||||
}
|
||||
else {
|
||||
int fd = -1;
|
||||
#ifdef _WIN32
|
||||
#define OPENMODE S_IREAD | S_IWRITE
|
||||
if(!_sopen_s(&fd, serverlogfile, O_WRONLY | O_CREAT | O_APPEND,
|
||||
_SH_DENYNO, S_IREAD | S_IWRITE) &&
|
||||
fd != -1) {
|
||||
#else
|
||||
#define OPENMODE S_IRUSR | S_IWUSR
|
||||
#endif
|
||||
int fd = open(serverlogfile, O_WRONLY | O_CREAT | O_APPEND, OPENMODE);
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
fd = open(serverlogfile,
|
||||
O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
|
||||
if(fd != -1) {
|
||||
#endif
|
||||
static const char msg[] = "exit_signal_handler: called\n";
|
||||
(void)!write(fd, msg, sizeof(msg) - 1);
|
||||
close(fd);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue