From: Viktor Szakats Date: Wed, 15 Jan 2025 09:52:02 +0000 (+0100) Subject: tidy-up: extend `CURL_O_BINARY` to lib and tests X-Git-Tag: curl-8_12_0~108 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f07612cd9ae1ec50b9bedd749171ad75203c9e7e;p=thirdparty%2Fcurl.git 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 --- diff --git a/lib/curl_setup.h b/lib/curl_setup.h index fe6188d39c..6864d5f56d 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -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 */ diff --git a/lib/file.c b/lib/file.c index b00c61a27b..d753a3d1c3 100644 --- a/lib/file.c +++ b/lib/file.c @@ -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__)) diff --git a/lib/vquic/vquic.c b/lib/vquic/vquic.c index bb06b76ab7..c0d6e2f3eb 100644 --- a/lib/vquic/vquic.c +++ b/lib/vquic/vquic.c @@ -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; diff --git a/src/tool_setup.h b/src/tool_setup.h index 1e04880455..8c89e60275 100644 --- a/src/tool_setup.h +++ b/src/tool_setup.h @@ -66,14 +66,6 @@ extern FILE *tool_stderr; # include "tool_strdup.h" #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 - #if defined(_WIN32) # define CURL_STRICMP(p1, p2) _stricmp(p1, p2) #elif defined(HAVE_STRCASECMP) diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index c1d639f697..b513ecc5cb 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -454,11 +454,7 @@ static ssize_t write_behind(struct testcase *test, int convert) if(!test->ofile) { char outfile[256]; msnprintf(outfile, sizeof(outfile), "%s/upload.%ld", logdir, test->testno); -#ifdef _WIN32 - test->ofile = open(outfile, O_CREAT|O_RDWR|O_BINARY, 0777); -#else - test->ofile = open(outfile, O_CREAT|O_RDWR, 0777); -#endif + test->ofile = open(outfile, O_CREAT|O_RDWR|CURL_O_BINARY, 0777); if(test->ofile == -1) { logmsg("Couldn't create and/or open file %s for upload!", outfile); return -1; /* failure! */