diff options
author | Maxim Yurchuk <maxim-yurchuk@ydb.tech> | 2024-10-04 17:24:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-04 17:24:16 +0300 |
commit | a1e4766748b5924d3879ab6a0259b28ec3c5d535 (patch) | |
tree | 4480150864228623d6c9101a4ba8c049bda9aa90 /contrib/libs/curl/src/tool_cb_wrt.c | |
parent | 6536467764bed7822214815ce92ed4dcd5bf409b (diff) | |
parent | a46fe128b9c9c84438fc2aac337aeefdaecb99df (diff) | |
download | ydb-a1e4766748b5924d3879ab6a0259b28ec3c5d535.tar.gz |
Merge pull request #10090 from ydb-platform/mergelibs-241004-1110
Library import 241004-1110
Diffstat (limited to 'contrib/libs/curl/src/tool_cb_wrt.c')
-rw-r--r-- | contrib/libs/curl/src/tool_cb_wrt.c | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/contrib/libs/curl/src/tool_cb_wrt.c b/contrib/libs/curl/src/tool_cb_wrt.c index 98063c39c2..e35489a39f 100644 --- a/contrib/libs/curl/src/tool_cb_wrt.c +++ b/contrib/libs/curl/src/tool_cb_wrt.c @@ -30,8 +30,6 @@ #include <sys/stat.h> -#define ENABLE_CURLX_PRINTF -/* use our own printf() functions */ #include "curlx.h" #include "tool_cfgable.h" @@ -56,24 +54,11 @@ bool tool_create_output_file(struct OutStruct *outs, { struct GlobalConfig *global; FILE *file = NULL; - char *fname = outs->filename; - char *aname = NULL; + const char *fname = outs->filename; DEBUGASSERT(outs); DEBUGASSERT(config); global = config->global; - if(!fname || !*fname) { - warnf(global, "Remote filename has no length"); - return FALSE; - } - - if(config->output_dir && outs->is_cd_filename) { - aname = aprintf("%s/%s", config->output_dir, fname); - if(!aname) { - errorf(global, "out of memory"); - return FALSE; - } - fname = aname; - } + DEBUGASSERT(fname && *fname); if(config->file_clobber_mode == CLOBBER_ALWAYS || (config->file_clobber_mode == CLOBBER_DEFAULT && @@ -85,7 +70,7 @@ bool tool_create_output_file(struct OutStruct *outs, int fd; do { fd = open(fname, O_CREAT | O_WRONLY | O_EXCL | O_BINARY, OPENMODE); - /* Keep retrying in the hope that it isn't interrupted sometime */ + /* Keep retrying in the hope that it is not interrupted sometime */ } while(fd == -1 && errno == EINTR); if(config->file_clobber_mode == CLOBBER_NEVER && fd == -1) { int next_num = 1; @@ -94,27 +79,25 @@ bool tool_create_output_file(struct OutStruct *outs, char *newname; /* Guard against wraparound in new filename */ if(newlen < len) { - free(aname); errorf(global, "overflow in filename generation"); return FALSE; } newname = malloc(newlen); if(!newname) { errorf(global, "out of memory"); - free(aname); return FALSE; } memcpy(newname, fname, len); newname[len] = '.'; - while(fd == -1 && /* haven't successfully opened a file */ + while(fd == -1 && /* have not successfully opened a file */ (errno == EEXIST || errno == EISDIR) && /* because we keep having files that already exist */ - next_num < 100 /* and we haven't reached the retry limit */ ) { - curlx_msnprintf(newname + len + 1, 12, "%d", next_num); + next_num < 100 /* and we have not reached the retry limit */ ) { + msnprintf(newname + len + 1, 12, "%d", next_num); next_num++; do { fd = open(newname, O_CREAT | O_WRONLY | O_EXCL | O_BINARY, OPENMODE); - /* Keep retrying in the hope that it isn't interrupted sometime */ + /* Keep retrying in the hope that it is not interrupted sometime */ } while(fd == -1 && errno == EINTR); } outs->filename = newname; /* remember the new one */ @@ -135,10 +118,8 @@ bool tool_create_output_file(struct OutStruct *outs, if(!file) { warnf(global, "Failed to open the file %s: %s", fname, strerror(errno)); - free(aname); return FALSE; } - free(aname); outs->s_isreg = TRUE; outs->fopened = TRUE; outs->stream = file; @@ -166,7 +147,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata) #ifdef DEBUGBUILD { - char *tty = curlx_getenv("CURL_ISATTY"); + char *tty = curl_getenv("CURL_ISATTY"); if(tty) { is_tty = TRUE; curl_free(tty); @@ -233,7 +214,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata) #ifdef _WIN32 fhnd = _get_osfhandle(fileno(outs->stream)); - /* if windows console then UTF-8 must be converted to UTF-16 */ + /* if Windows console then UTF-8 must be converted to UTF-16 */ if(isatty(fileno(outs->stream)) && GetConsoleScreenBufferInfo((HANDLE)fhnd, &console_info)) { wchar_t *wc_buf; @@ -332,7 +313,8 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata) if(rlen) { /* calculate buffer size for wide characters */ - wc_len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)rbuf, rlen, NULL, 0); + wc_len = (DWORD)MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)rbuf, (int)rlen, + NULL, 0); if(!wc_len) return CURL_WRITEFUNC_ERROR; @@ -340,8 +322,8 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata) if(!wc_buf) return CURL_WRITEFUNC_ERROR; - wc_len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)rbuf, rlen, wc_buf, - wc_len); + wc_len = (DWORD)MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)rbuf, (int)rlen, + wc_buf, (int)wc_len); if(!wc_len) { free(wc_buf); return CURL_WRITEFUNC_ERROR; |