curl/lib/curlx
Viktor Szakats 6d0ee7b17b
curlx: add curlx_rename(), fix to support long filenames on Windows
Move existing `Curl_rename()` `rename()` wrapper from lib to
curlx/fopen, and make it a curlx macro/function. To allow using
the local worker function to fixup long filenames on Windows.

Then fix the Windows-specific rename implementation to support long
filenames. This operation may happen when using a cookie jar, HSTS cache
or alt-svc cache, via libcurl or the curl tool.

Before this patch, when passing a long filename to the above options,
a `<random>.tmp` file was left on the disk without renaming it to the
filename passed to curl. There was also 1 second delay for each
attempted rename operation.

Also:
- checksrc: ban raw `rename()` and `MoveFileEx*()` functions.
- Note: `Curl_rename()` returned 1 on failure before this patch, while
  `curlx_rename()` returns -1 after, to match POSIX `rename()`.

Refs:
https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-movefileexa
https://learn.microsoft.com/windows/win32/fileio/maximum-file-path-limitation

Ref: #20040

Closes #20042
2025-12-20 16:03:11 +01:00
..
base64.c build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
base64.h curlx_base64_encode: use uint8_t* for input 2025-11-27 14:35:01 +01:00
binmode.h lib: make CURLX_SET_BINMODE() and use it 2025-06-19 15:57:37 +02:00
curlx.h curlx: limit use of system allocators to the minimum possible 2025-12-05 15:32:59 +01:00
dynbuf.c lib/subdirs: fix formatting nits 2025-11-30 11:01:50 +01:00
dynbuf.h build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
fopen.c curlx: add curlx_rename(), fix to support long filenames on Windows 2025-12-20 16:03:11 +01:00
fopen.h curlx: add curlx_rename(), fix to support long filenames on Windows 2025-12-20 16:03:11 +01:00
inet_ntop.c lib/subdirs: fix formatting nits 2025-11-30 11:01:50 +01:00
inet_ntop.h lib/subdirs: fix formatting nits 2025-11-30 11:01:50 +01:00
inet_pton.c lib/subdirs: fix formatting nits 2025-11-30 11:01:50 +01:00
inet_pton.h lib/subdirs: fix formatting nits 2025-11-30 11:01:50 +01:00
multibyte.c curlx: limit use of system allocators to the minimum possible 2025-12-05 15:32:59 +01:00
multibyte.h tidy-up: avoid (()), clang-format fixes and more 2025-12-05 16:07:03 +01:00
nonblock.c lib/subdirs: fix formatting nits 2025-11-30 11:01:50 +01:00
nonblock.h build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
snprintf.h curlx: replace sprintf with snprintf 2025-11-25 11:11:06 +01:00
strerr.c build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
strerr.h curlx: move Curl_strerror, use in src and tests, ban strerror globally 2025-10-06 09:44:23 +02:00
strparse.c build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
strparse.h tidy-up: avoid (()), clang-format fixes and more 2025-12-05 16:07:03 +01:00
timediff.c build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
timediff.h curlx: move into to curlx/ 2025-05-07 11:01:15 +02:00
timeval.c build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
timeval.h time-keeping: keep timestamp in multi, always update 2025-12-18 22:10:06 +01:00
version_win32.c build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
version_win32.h curlx: move version_win32.[ch] to curlx/ 2025-05-08 17:09:32 +02:00
wait.c build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
wait.h lib: make curlx_wait_ms() and use it 2025-06-19 15:57:37 +02:00
warnless.c build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
warnless.h build: drop duplicate include curl/curl.h and others 2025-12-19 10:58:11 +01:00
winapi.c lib/subdirs: fix formatting nits 2025-11-30 11:01:50 +01:00
winapi.h windows: use native error code types more 2025-10-06 12:12:44 +02:00