Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/scripts/codespell-ignore.words
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
anonymou
aNULL
bu
Buss
clen
CNA
hel
Expand Down
1 change: 1 addition & 0 deletions .github/scripts/codespell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ codespell \
--skip 'docs/THANKS' \
--skip 'projects/OS400/*' \
--skip 'projects/vms/*' \
--skip 'RELEASE-NOTES' \
--skip 'scripts/wcurl' \
--ignore-regex '.*spellchecker:disable-line' \
--ignore-words '.github/scripts/codespell-ignore.words' \
Expand Down
1 change: 0 additions & 1 deletion CMake/win32-cache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ set(HAVE_SIGSETJMP 0)
set(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1)
set(HAVE_SOCKET 1)
set(HAVE_SOCKETPAIR 0)
set(HAVE_STRDUP 1)
set(HAVE_STRERROR_R 0)
set(HAVE_STROPTS_H 0)
set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
Expand Down
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ if(WIN32)

# Apply to all feature checks
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DWIN32_LEAN_AND_MEAN")
if(MSVC)
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_CRT_NONSTDC_NO_DEPRECATE") # for strdup() detection
endif()

set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
if(CURL_TARGET_WINDOWS_VERSION)
Expand Down Expand Up @@ -1537,7 +1534,6 @@ check_symbol_exists("send" "${CURL_INCLUDES}" HAVE_SEND) # proto/bsd
check_function_exists("sendmsg" HAVE_SENDMSG)
check_function_exists("sendmmsg" HAVE_SENDMMSG)
check_symbol_exists("select" "${CURL_INCLUDES}" HAVE_SELECT) # proto/bsdsocket.h sys/select.h sys/socket.h
check_symbol_exists("strdup" "string.h" HAVE_STRDUP)
check_symbol_exists("memrchr" "string.h" HAVE_MEMRCHR)
check_symbol_exists("alarm" "unistd.h" HAVE_ALARM)
check_symbol_exists("fcntl" "fcntl.h" HAVE_FCNTL)
Expand Down Expand Up @@ -1575,11 +1571,14 @@ check_function_exists("getrlimit" HAVE_GETRLIMIT)
check_function_exists("setlocale" HAVE_SETLOCALE)
check_function_exists("setrlimit" HAVE_SETRLIMIT)

if(NOT WIN32)
if(WIN32)
set(HAVE_STRDUP 1) # to not define local implementation. curl uses _strdup() on Windows.
else()
check_function_exists("if_nametoindex" HAVE_IF_NAMETOINDEX) # net/if.h
check_function_exists("realpath" HAVE_REALPATH)
check_function_exists("sched_yield" HAVE_SCHED_YIELD)
check_symbol_exists("strcasecmp" "string.h" HAVE_STRCASECMP)
check_symbol_exists("strdup" "string.h" HAVE_STRDUP)
check_symbol_exists("stricmp" "string.h" HAVE_STRICMP)
check_symbol_exists("strcmpi" "string.h" HAVE_STRCMPI)
endif()
Expand Down
1 change: 1 addition & 0 deletions docs/examples/.checksrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
allowfunc atoi
allowfunc atol
allowfunc calloc
allowfunc close
allowfunc fclose
allowfunc fdopen
allowfunc fopen
Expand Down
1 change: 1 addition & 0 deletions docs/internals/CODE_STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ This is the full list of functions generally banned.
atoi
atol
calloc
close
CreateFile
CreateFileA
CreateFileW
Expand Down
2 changes: 1 addition & 1 deletion lib/cf-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ static CURLcode socket_open(struct Curl_easy *data,
if(fcntl(*sockfd, F_SETFD, FD_CLOEXEC) < 0) {
failf(data, "fcntl set CLOEXEC: %s",
curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf)));
close(*sockfd);
sclose(*sockfd);
*sockfd = CURL_SOCKET_BAD;
return CURLE_COULDNT_CONNECT;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/curl_fopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename,

fail:
if(fd != -1) {
close(fd);
curlx_close(fd);
unlink(tempstore);
}

Expand Down
11 changes: 7 additions & 4 deletions lib/curl_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@
#ifdef _MSC_VER
/* Disable Visual Studio warnings: 4127 "conditional expression is constant" */
#pragma warning(disable:4127)
/* Avoid VS2005 and upper complaining about portable C functions. */
#ifndef _CRT_NONSTDC_NO_DEPRECATE /* mingw-w64 v2+. MS SDK ~10+/~VS2017+. */
#define _CRT_NONSTDC_NO_DEPRECATE /* for close(), fileno(), unlink(), etc. */
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS /* for getenv(), tests: sscanf() */
#endif
Expand Down Expand Up @@ -808,6 +804,13 @@
# define read(fd, buf, count) (ssize_t)_read(fd, buf, curlx_uztoui(count))
# undef write
# define write(fd, buf, count) (ssize_t)_write(fd, buf, curlx_uztoui(count))
/* Avoid VS2005+ _CRT_NONSTDC_NO_DEPRECATE warnings about non-portable funcs */
# undef fileno
# define fileno(fh) _fileno(fh)
# undef unlink
# define unlink(fn) _unlink(fn)
# undef isatty
# define isatty(fd) _isatty(fd)
#endif

/*
Expand Down
6 changes: 5 additions & 1 deletion lib/curlx/fopen.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,18 @@ int curlx_win32_open(const char *filename, int oflag, ...);
int curlx_win32_rename(const char *oldpath, const char *newpath);
#define CURLX_FOPEN_LOW(fname, mode) curlx_win32_fopen(fname, mode)
#define CURLX_FREOPEN_LOW(fname, mode, fh) curlx_win32_freopen(fname, mode, fh)
#define CURLX_FDOPEN_LOW _fdopen
#define curlx_stat(fname, stp) curlx_win32_stat(fname, stp)
#define curlx_open curlx_win32_open
#define curlx_close _close
#define curlx_rename curlx_win32_rename
#else
#define CURLX_FOPEN_LOW fopen
#define CURLX_FREOPEN_LOW freopen
#define CURLX_FDOPEN_LOW fdopen
#define curlx_stat(fname, stp) stat(fname, stp)
#define curlx_open open
#define curlx_close close
#define curlx_rename rename
#endif

Expand All @@ -71,7 +75,7 @@ int curlx_win32_rename(const char *oldpath, const char *newpath);
#else
#define curlx_fopen CURLX_FOPEN_LOW
#define curlx_freopen CURLX_FREOPEN_LOW
#define curlx_fdopen fdopen
#define curlx_fdopen CURLX_FDOPEN_LOW
#define curlx_fclose fclose
#endif

Expand Down
4 changes: 1 addition & 3 deletions lib/easy.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@ static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT;
* ways, but at this point it must be defined as the system-supplied strdup
* so the callback pointer is initialized correctly.
*/
#ifdef HAVE_STRDUP
#ifdef _WIN32
#define system_strdup _strdup
#else
#elif defined(HAVE_STRDUP)
#define system_strdup strdup
#endif
#else
#define system_strdup Curl_strdup
#endif
Expand Down
6 changes: 3 additions & 3 deletions lib/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void file_cleanup(struct FILEPROTO *file)
Curl_safefree(file->freepath);
file->path = NULL;
if(file->fd != -1) {
close(file->fd);
curlx_close(file->fd);
file->fd = -1;
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ static CURLcode file_upload(struct Curl_easy *data,
/* treat the negative resume offset value as the case of "-" */
if(data->state.resume_from < 0) {
if(fstat(fd, &file_stat)) {
close(fd);
curlx_close(fd);
failf(data, "cannot get the size of %s", file->path);
return CURLE_WRITE_ERROR;
}
Expand Down Expand Up @@ -367,7 +367,7 @@ static CURLcode file_upload(struct Curl_easy *data,
result = Curl_pgrsUpdate(data);

out:
close(fd);
curlx_close(fd);
Curl_multi_xfer_ulbuf_release(data, xfer_ulbuf);

return result;
Expand Down
3 changes: 1 addition & 2 deletions lib/memdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,7 @@ ALLOC_FUNC
FILE *curl_dbg_fdopen(int filedes, const char *mode,
int line, const char *source)
{
/* !checksrc! disable BANNEDFUNC 1 */
FILE *res = fdopen(filedes, mode);
FILE *res = CURLX_FDOPEN_LOW(filedes, mode);
if(source)
curl_dbg_log("FILE %s:%d fdopen(\"%d\",\"%s\") = %p\n",
source, line, filedes, mode, (void *)res);
Expand Down
12 changes: 6 additions & 6 deletions lib/socketpair.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ static int wakeup_pipe(curl_socket_t socks[2], bool nonblocking)
#ifdef HAVE_FCNTL
if(fcntl(socks[0], F_SETFD, FD_CLOEXEC) ||
fcntl(socks[1], F_SETFD, FD_CLOEXEC)) {
close(socks[0]);
close(socks[1]);
sclose(socks[0]);
sclose(socks[1]);
socks[0] = socks[1] = CURL_SOCKET_BAD;
return -1;
}
#endif
if(nonblocking) {
if(curlx_nonblock(socks[0], TRUE) < 0 ||
curlx_nonblock(socks[1], TRUE) < 0) {
close(socks[0]);
close(socks[1]);
sclose(socks[0]);
sclose(socks[1]);
socks[0] = socks[1] = CURL_SOCKET_BAD;
return -1;
}
Expand Down Expand Up @@ -107,8 +107,8 @@ static int wakeup_socketpair(curl_socket_t socks[2], bool nonblocking)
if(nonblocking) {
if(curlx_nonblock(socks[0], TRUE) < 0 ||
curlx_nonblock(socks[1], TRUE) < 0) {
close(socks[0]);
close(socks[1]);
sclose(socks[0]);
sclose(socks[1]);
return -1;
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/vquic/curl_ngtcp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "../cf-socket.h"
#include "../connect.h"
#include "../progress.h"
#include "../curlx/fopen.h"
#include "../curlx/dynbuf.h"
#include "../http1.h"
#include "../select.h"
Expand Down Expand Up @@ -449,7 +450,7 @@ static void qlog_callback(void *user_data, uint32_t flags,
ssize_t rc = write(ctx->qlogfd, data, datalen);
if(rc == -1) {
/* on write error, stop further write attempts */
close(ctx->qlogfd);
curlx_close(ctx->qlogfd);
ctx->qlogfd = -1;
}
}
Expand Down Expand Up @@ -2140,7 +2141,7 @@ static void cf_ngtcp2_ctx_close(struct cf_ngtcp2_ctx *ctx)
if(!ctx->initialized)
return;
if(ctx->qlogfd != -1) {
close(ctx->qlogfd);
curlx_close(ctx->qlogfd);
}
ctx->qlogfd = -1;
Curl_vquic_tls_cleanup(&ctx->tls);
Expand Down
1 change: 1 addition & 0 deletions scripts/checksrc.pl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"atoi" => 1,
"atol" => 1,
"calloc" => 1,
"close" => 1,
"CreateFile" => 1,
"CreateFileA" => 1,
"CreateFileW" => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/tool_cb_wrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool tool_create_output_file(struct OutStruct *outs,
if(fd != -1) {
file = curlx_fdopen(fd, "wb");
if(!file)
close(fd);
curlx_close(fd);
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/tool_dirhie.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
***************************************************************************/
#include "tool_setup.h"

#ifdef _WIN32
#include <direct.h>
#endif

#include "tool_dirhie.h"
#include "tool_msgs.h"

#if defined(_WIN32) || (defined(MSDOS) && !defined(__DJGPP__))
#ifdef _WIN32
# include <direct.h>
# define mkdir(x, y) _mkdir(x)
#elif defined(MSDOS) && !defined(__DJGPP__)
# define mkdir(x, y) (mkdir)(x)
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/tool_findfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static char *checkhome(const char *home, const char *fname, bool dotscore)
int fd = curlx_open(c, O_RDONLY);
if(fd >= 0) {
char *path = curlx_strdup(c);
close(fd);
curlx_close(fd);
curl_free(c);
return path;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tool_getpass.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ char *getpass_r(const char *prompt, /* prompt to display */
}

if(STDIN_FILENO != fd)
close(fd);
curlx_close(fd);

return password; /* return pointer to buffer */
}
Expand Down
4 changes: 2 additions & 2 deletions src/tool_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static CURLcode pre_transfer(struct per_transfer *per)
{
helpf("cannot open '%s'", per->uploadfile);
if(per->infd != -1) {
close(per->infd);
curlx_close(per->infd);
per->infd = STDIN_FILENO;
}
return CURLE_READ_ERROR;
Expand Down Expand Up @@ -621,7 +621,7 @@ static CURLcode post_per_transfer(struct per_transfer *per,
else
#endif
if(per->infdopen)
close(per->infd);
curlx_close(per->infd);

if(per->skip)
goto skip;
Expand Down
4 changes: 2 additions & 2 deletions tests/libtest/lib518.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void t518_close_file_descriptors(void)
t518_num_open.rlim_cur < t518_num_open.rlim_max;
t518_num_open.rlim_cur++)
if(t518_testfd[t518_num_open.rlim_cur] > 0)
close(t518_testfd[t518_num_open.rlim_cur]);
curlx_close(t518_testfd[t518_num_open.rlim_cur]);
curlx_free(t518_testfd);
t518_testfd = NULL;
}
Expand Down Expand Up @@ -333,7 +333,7 @@ static int t518_test_rlimit(int keep_open)
for(t518_num_open.rlim_cur = 0;
t518_testfd[t518_num_open.rlim_cur] >= 0;
t518_num_open.rlim_cur++)
close(t518_testfd[t518_num_open.rlim_cur]);
curlx_close(t518_testfd[t518_num_open.rlim_cur]);
curlx_free(t518_testfd);
t518_testfd = NULL;
curlx_free(memchunk);
Expand Down
4 changes: 2 additions & 2 deletions tests/libtest/lib537.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void t537_close_file_descriptors(void)
t537_num_open.rlim_cur < t537_num_open.rlim_max;
t537_num_open.rlim_cur++)
if(t537_testfd[t537_num_open.rlim_cur] > 0)
close(t537_testfd[t537_num_open.rlim_cur]);
curlx_close(t537_testfd[t537_num_open.rlim_cur]);
curlx_free(t537_testfd);
t537_testfd = NULL;
}
Expand Down Expand Up @@ -334,7 +334,7 @@ static int t537_test_rlimit(int keep_open)
for(t537_num_open.rlim_cur = t537_num_open.rlim_max;
t537_testfd[t537_num_open.rlim_cur] >= 0;
t537_num_open.rlim_cur++) {
close(t537_testfd[t537_num_open.rlim_cur]);
curlx_close(t537_testfd[t537_num_open.rlim_cur]);
t537_testfd[t537_num_open.rlim_cur] = -1;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/libtest/lib568.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static CURLcode test_lib568(const char *URL)
goto test_cleanup;
}
fstat(sdp, &file_info);
close(sdp);
curlx_close(sdp);

sdpf = curlx_fopen(libtest_arg2, "rb");
if(!sdpf) {
Expand Down
2 changes: 1 addition & 1 deletion tests/libtest/lib572.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static CURLcode test_lib572(const char *URL)
goto test_cleanup;
}
fstat(params, &file_info);
close(params);
curlx_close(params);

paramsf = curlx_fopen(libtest_arg2, "rb");
if(!paramsf) {
Expand Down
Loading