tidy-up: extend CURL_O_BINARY to lib and tests

Move `CURL_O_BINARY` definition from src to lib and use it from lib and
tests code.

Closes #16009
This commit is contained in:
Viktor Szakats 2025-01-15 10:52:02 +01:00
parent c5bb4e77e4
commit f07612cd9a
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
5 changed files with 14 additions and 29 deletions

View file

@ -886,6 +886,14 @@
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
/* Since O_BINARY is used in bitmasks, setting it to zero makes it usable in
source code but yet it does not ruin anything */
#ifdef O_BINARY
#define CURL_O_BINARY O_BINARY
#else
#define CURL_O_BINARY 0
#endif
/* In Windows the default file mode is text but an application can override it.
Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
*/

View file

@ -203,7 +203,7 @@ static CURLcode file_connect(struct Curl_easy *data, bool *done)
return CURLE_URL_MALFORMAT;
}
fd = open(actual_path, O_RDONLY|O_BINARY);
fd = open(actual_path, O_RDONLY|CURL_O_BINARY);
file->path = actual_path;
#else
if(memchr(real_path, 0, real_path_len)) {
@ -312,16 +312,11 @@ static CURLcode file_upload(struct Curl_easy *data)
if(!dir[1])
return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */
#ifdef O_BINARY
#define MODE_DEFAULT O_WRONLY|O_CREAT|O_BINARY
#else
#define MODE_DEFAULT O_WRONLY|O_CREAT
#endif
mode = O_WRONLY|O_CREAT|CURL_O_BINARY;
if(data->state.resume_from)
mode = MODE_DEFAULT|O_APPEND;
mode |= O_APPEND;
else
mode = MODE_DEFAULT|O_TRUNC;
mode |= O_TRUNC;
#if (defined(ANDROID) || defined(__ANDROID__)) && \
(defined(__i386__) || defined(__arm__))

View file

@ -53,12 +53,6 @@
#ifdef USE_HTTP3
#ifdef O_BINARY
#define QLOGMODE O_WRONLY|O_CREAT|O_BINARY
#else
#define QLOGMODE O_WRONLY|O_CREAT
#endif
#define NW_CHUNK_SIZE (64 * 1024)
#define NW_SEND_CHUNKS 2
@ -657,7 +651,7 @@ CURLcode Curl_qlogdir(struct Curl_easy *data,
result = Curl_dyn_add(&fname, ".sqlog");
if(!result) {
int qlogfd = open(Curl_dyn_ptr(&fname), QLOGMODE,
int qlogfd = open(Curl_dyn_ptr(&fname), O_WRONLY|O_CREAT|CURL_O_BINARY,
data->set.new_file_perms);
if(qlogfd != -1)
*qlogfdp = qlogfd;