From: Daniel Stenberg Date: Sun, 25 Jan 2026 10:17:32 +0000 (+0100) Subject: tool: return code variable consistency X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0dc6e2ec059bf306f32e7a49e9ff7425cd26fcd;p=thirdparty%2Fcurl.git tool: return code variable consistency - ParameterError variables are named 'err' - CURLcode variables are named 'result' For naming consistency across functions Closes #20426 --- diff --git a/src/tool_easysrc.c b/src/tool_easysrc.c index 2a2d3109a0..593ceb7957 100644 --- a/src/tool_easysrc.c +++ b/src/tool_easysrc.c @@ -90,33 +90,33 @@ static void easysrc_free(void) /* Add a source line to the main code or remarks */ CURLcode easysrc_add(struct slist_wc **plist, const char *line) { - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; struct slist_wc *list = slist_wc_append(*plist, line); if(!list) { easysrc_free(); - ret = CURLE_OUT_OF_MEMORY; + result = CURLE_OUT_OF_MEMORY; } else *plist = list; - return ret; + return result; } CURLcode easysrc_addf(struct slist_wc **plist, const char *fmt, ...) { - CURLcode ret; + CURLcode result; char *bufp; va_list ap; va_start(ap, fmt); bufp = curl_mvaprintf(fmt, ap); va_end(ap); if(!bufp) { - ret = CURLE_OUT_OF_MEMORY; + result = CURLE_OUT_OF_MEMORY; } else { - ret = easysrc_add(plist, bufp); + result = easysrc_add(plist, bufp); curl_free(bufp); } - return ret; + return result; } CURLcode easysrc_init(void) @@ -126,46 +126,46 @@ CURLcode easysrc_init(void) CURLcode easysrc_perform(void) { - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; /* Note any setopt calls which we could not convert */ if(easysrc_toohard) { int i; struct curl_slist *ptr; - ret = easysrc_add(&easysrc_code, ""); + result = easysrc_add(&easysrc_code, ""); /* Preamble comment */ - for(i = 0; srchard[i] && !ret; i++) - ret = easysrc_add(&easysrc_code, srchard[i]); + for(i = 0; srchard[i] && !result; i++) + result = easysrc_add(&easysrc_code, srchard[i]); /* Each unconverted option */ - if(easysrc_toohard && !ret) { - for(ptr = easysrc_toohard->first; ptr && !ret; ptr = ptr->next) - ret = easysrc_add(&easysrc_code, ptr->data); + if(easysrc_toohard && !result) { + for(ptr = easysrc_toohard->first; ptr && !result; ptr = ptr->next) + result = easysrc_add(&easysrc_code, ptr->data); } - if(!ret) - ret = easysrc_add(&easysrc_code, ""); - if(!ret) - ret = easysrc_add(&easysrc_code, "*/"); + if(!result) + result = easysrc_add(&easysrc_code, ""); + if(!result) + result = easysrc_add(&easysrc_code, "*/"); slist_wc_free_all(easysrc_toohard); easysrc_toohard = NULL; } - if(!ret) - ret = easysrc_add(&easysrc_code, ""); - if(!ret) - ret = easysrc_add(&easysrc_code, "ret = curl_easy_perform(hnd);"); - if(!ret) - ret = easysrc_add(&easysrc_code, ""); + if(!result) + result = easysrc_add(&easysrc_code, ""); + if(!result) + result = easysrc_add(&easysrc_code, "ret = curl_easy_perform(hnd);"); + if(!result) + result = easysrc_add(&easysrc_code, ""); - return ret; + return result; } CURLcode easysrc_cleanup(void) { - CURLcode ret = easysrc_add(&easysrc_code, "curl_easy_cleanup(hnd);"); - if(!ret) - ret = easysrc_add(&easysrc_code, "hnd = NULL;"); + CURLcode result = easysrc_add(&easysrc_code, "curl_easy_cleanup(hnd);"); + if(!result) + result = easysrc_add(&easysrc_code, "hnd = NULL;"); - return ret; + return result; } void dumpeasysrc(void) diff --git a/src/tool_formparse.c b/src/tool_formparse.c index 659f6e35a4..5714ae5bc1 100644 --- a/src/tool_formparse.c +++ b/src/tool_formparse.c @@ -253,39 +253,39 @@ int tool_mime_stdin_seek(void *instream, curl_off_t offset, int whence) static CURLcode tool2curlparts(CURL *curl, struct tool_mime *m, curl_mime *mime) { - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; curl_mimepart *part = NULL; curl_mime *submime = NULL; const char *filename = NULL; if(m) { - ret = tool2curlparts(curl, m->prev, mime); - if(!ret) { + result = tool2curlparts(curl, m->prev, mime); + if(!result) { part = curl_mime_addpart(mime); if(!part) - ret = CURLE_OUT_OF_MEMORY; + result = CURLE_OUT_OF_MEMORY; } - if(!ret) { + if(!result) { filename = m->filename; switch(m->kind) { case TOOLMIME_PARTS: - ret = tool2curlmime(curl, m, &submime); - if(!ret) { - ret = curl_mime_subparts(part, submime); - if(ret) + result = tool2curlmime(curl, m, &submime); + if(!result) { + result = curl_mime_subparts(part, submime); + if(result) curl_mime_free(submime); } break; case TOOLMIME_DATA: - ret = curl_mime_data(part, m->data, CURL_ZERO_TERMINATED); + result = curl_mime_data(part, m->data, CURL_ZERO_TERMINATED); break; case TOOLMIME_FILE: case TOOLMIME_FILEDATA: - ret = curl_mime_filedata(part, m->data); - if(!ret && m->kind == TOOLMIME_FILEDATA && !filename) - ret = curl_mime_filename(part, NULL); + result = curl_mime_filedata(part, m->data); + if(!result && m->kind == TOOLMIME_FILEDATA && !filename) + result = curl_mime_filename(part, NULL); break; case TOOLMIME_STDIN: @@ -293,10 +293,10 @@ static CURLcode tool2curlparts(CURL *curl, struct tool_mime *m, filename = "-"; FALLTHROUGH(); case TOOLMIME_STDINDATA: - ret = curl_mime_data_cb(part, m->size, - (curl_read_callback)tool_mime_stdin_read, - (curl_seek_callback)tool_mime_stdin_seek, - NULL, m); + result = curl_mime_data_cb(part, m->size, + (curl_read_callback)tool_mime_stdin_read, + (curl_seek_callback)tool_mime_stdin_seek, + NULL, m); break; default: @@ -304,34 +304,34 @@ static CURLcode tool2curlparts(CURL *curl, struct tool_mime *m, break; } } - if(!ret && filename) - ret = curl_mime_filename(part, filename); - if(!ret) - ret = curl_mime_type(part, m->type); - if(!ret) - ret = curl_mime_headers(part, m->headers, 0); - if(!ret) - ret = curl_mime_encoder(part, m->encoder); - if(!ret) - ret = curl_mime_name(part, m->name); + if(!result && filename) + result = curl_mime_filename(part, filename); + if(!result) + result = curl_mime_type(part, m->type); + if(!result) + result = curl_mime_headers(part, m->headers, 0); + if(!result) + result = curl_mime_encoder(part, m->encoder); + if(!result) + result = curl_mime_name(part, m->name); } - return ret; + return result; } CURLcode tool2curlmime(CURL *curl, struct tool_mime *m, curl_mime **mime) { - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; *mime = curl_mime_init(curl); if(!*mime) - ret = CURLE_OUT_OF_MEMORY; + result = CURLE_OUT_OF_MEMORY; else - ret = tool2curlparts(curl, m->subparts, *mime); - if(ret) { + result = tool2curlparts(curl, m->subparts, *mime); + if(result) { curl_mime_free(*mime); *mime = NULL; } - return ret; + return result; } /* @@ -727,7 +727,7 @@ int formparse(const char *input, char *encoder = NULL; struct curl_slist *headers = NULL; struct tool_mime *part = NULL; - CURLcode res; + CURLcode result; int err = 1; /* Allocate the main mime structure if needed. */ @@ -801,12 +801,12 @@ int formparse(const char *input, } /* Store that file in a part. */ - part = tool_mime_new_filedata(subparts, data, TRUE, &res); + part = tool_mime_new_filedata(subparts, data, TRUE, &result); if(!part) goto fail; part->headers = headers; headers = NULL; - if(res == CURLE_READ_ERROR) { + if(result == CURLE_READ_ERROR) { /* An error occurred while reading stdin: if read has started, issue the error now. Else, delay it until processed by libcurl. */ if(part->size > 0) { @@ -815,7 +815,7 @@ int formparse(const char *input, } tool_safefree(part->data); part->size = -1; - res = CURLE_OK; + result = CURLE_OK; } SET_TOOL_MIME_PTR(part, filename); SET_TOOL_MIME_PTR(part, type); @@ -833,12 +833,12 @@ int formparse(const char *input, if(sep < 0) goto fail; - part = tool_mime_new_filedata(*mimecurrent, data, FALSE, &res); + part = tool_mime_new_filedata(*mimecurrent, data, FALSE, &result); if(!part) goto fail; part->headers = headers; headers = NULL; - if(res == CURLE_READ_ERROR) { + if(result == CURLE_READ_ERROR) { /* An error occurred while reading stdin: if read has started, issue the error now. Else, delay it until processed by libcurl. */ @@ -848,7 +848,7 @@ int formparse(const char *input, } tool_safefree(part->data); part->size = -1; - res = CURLE_OK; + result = CURLE_OK; } } else { diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 991e769d68..47fe955615 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -3055,10 +3055,10 @@ ParameterError parse_args(int argc, argv_item_t argv[]) int i; bool stillflags; const char *orig_opt = NULL; - ParameterError result = PARAM_OK; + ParameterError err = PARAM_OK; struct OperationConfig *config = global->first; - for(i = 1, stillflags = TRUE; i < argc && !result; i++) { + for(i = 1, stillflags = TRUE; i < argc && !err; i++) { orig_opt = convert_tchar_to_UTF8(argv[i]); if(!orig_opt) return PARAM_NO_MEM; @@ -3080,15 +3080,15 @@ ParameterError parse_args(int argc, argv_item_t argv[]) } } - result = getparameter(orig_opt, nextarg, &passarg, config, + err = getparameter(orig_opt, nextarg, &passarg, config, CONFIG_MAX_LEVELS); unicodefree(CURL_UNCONST(nextarg)); config = global->last; - if(result == PARAM_NEXT_OPERATION) { - /* Reset result as PARAM_NEXT_OPERATION is only used here and not + if(err == PARAM_NEXT_OPERATION) { + /* Reset err as PARAM_NEXT_OPERATION is only used here and not returned from this function */ - result = PARAM_OK; + err = PARAM_OK; if(config->url_list && config->url_list->url) { /* Allocate the next config */ @@ -3102,14 +3102,14 @@ ParameterError parse_args(int argc, argv_item_t argv[]) config = config->next; } else - result = PARAM_NO_MEM; + err = PARAM_NO_MEM; } else { errorf("missing URL before --next"); - result = PARAM_BAD_USE; + err = PARAM_BAD_USE; } } - else if(!result && passarg) + else if(!err && passarg) i++; /* we are supposed to skip this */ } } @@ -3117,26 +3117,26 @@ ParameterError parse_args(int argc, argv_item_t argv[]) bool used; /* Just add the URL please */ - result = getparameter("--url", orig_opt, &used, config, 0); + err = getparameter("--url", orig_opt, &used, config, 0); } - if(!result) { + if(!err) { unicodefree(CURL_UNCONST(orig_opt)); orig_opt = NULL; } } - if(!result && config->content_disposition) { + if(!err && config->content_disposition) { if(config->resume_from_current) - result = PARAM_CONTDISP_RESUME_FROM; + err = PARAM_CONTDISP_RESUME_FROM; } - if(result && result != PARAM_HELP_REQUESTED && - result != PARAM_MANUAL_REQUESTED && - result != PARAM_VERSION_INFO_REQUESTED && - result != PARAM_ENGINES_REQUESTED && - result != PARAM_CA_EMBED_REQUESTED) { - const char *reason = param2text(result); + if(err && err != PARAM_HELP_REQUESTED && + err != PARAM_MANUAL_REQUESTED && + err != PARAM_VERSION_INFO_REQUESTED && + err != PARAM_ENGINES_REQUESTED && + err != PARAM_CA_EMBED_REQUESTED) { + const char *reason = param2text(err); if(orig_opt && strcmp(":", orig_opt)) helpf("option %s: %s", orig_opt, reason); @@ -3145,5 +3145,5 @@ ParameterError parse_args(int argc, argv_item_t argv[]) } unicodefree(CURL_UNCONST(orig_opt)); - return result; + return err; } diff --git a/src/tool_operate.c b/src/tool_operate.c index 1cddf47b00..0998303774 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -2270,20 +2270,20 @@ CURLcode operate(int argc, argv_item_t argv[]) if(!result) { /* Parse the command line arguments */ - ParameterError res = parse_args(argc, argv); + ParameterError err = parse_args(argc, argv); if(found_curlrc) { /* After parse_args so notef knows the verbosity */ notef("Read config file from '%s'", curlrc_path); curlx_free(curlrc_path); } - if(res) { + if(err) { result = CURLE_OK; /* Check if we were asked for the help */ - if(res == PARAM_HELP_REQUESTED) + if(err == PARAM_HELP_REQUESTED) ; /* already done */ /* Check if we were asked for the manual */ - else if(res == PARAM_MANUAL_REQUESTED) { + else if(err == PARAM_MANUAL_REQUESTED) { #ifdef USE_MANUAL hugehelp(); #else @@ -2291,20 +2291,20 @@ CURLcode operate(int argc, argv_item_t argv[]) #endif } /* Check if we were asked for the version information */ - else if(res == PARAM_VERSION_INFO_REQUESTED) + else if(err == PARAM_VERSION_INFO_REQUESTED) tool_version_info(); /* Check if we were asked to list the SSL engines */ - else if(res == PARAM_ENGINES_REQUESTED) + else if(err == PARAM_ENGINES_REQUESTED) tool_list_engines(); /* Check if we were asked to dump the embedded CA bundle */ - else if(res == PARAM_CA_EMBED_REQUESTED) { + else if(err == PARAM_CA_EMBED_REQUESTED) { #ifdef CURL_CA_EMBED curl_mprintf("%s", curl_ca_embed); #endif } - else if(res == PARAM_LIBCURL_UNSUPPORTED_PROTOCOL) + else if(err == PARAM_LIBCURL_UNSUPPORTED_PROTOCOL) result = CURLE_UNSUPPORTED_PROTOCOL; - else if(res == PARAM_READ_ERROR) + else if(err == PARAM_READ_ERROR) result = CURLE_READ_ERROR; else result = CURLE_FAILED_INIT; diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 753feca424..523b52629c 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -251,9 +251,9 @@ ParameterError oct2nummax(long *val, const char *str, long max) ParameterError str2unum(long *val, const char *str) { - ParameterError result = str2num(val, str); - if(result != PARAM_OK) - return result; + ParameterError err = str2num(val, str); + if(err != PARAM_OK) + return err; if(*val < 0) return PARAM_NEGATIVE_NUMERIC; @@ -272,9 +272,9 @@ ParameterError str2unum(long *val, const char *str) ParameterError str2unummax(long *val, const char *str, long max) { - ParameterError result = str2unum(val, str); - if(result != PARAM_OK) - return result; + ParameterError err = str2unum(val, str); + if(err != PARAM_OK) + return err; if(*val > max) return PARAM_NUMBER_TOO_LARGE; diff --git a/src/tool_setopt.c b/src/tool_setopt.c index b50f1a6f81..d9243ddf26 100644 --- a/src/tool_setopt.c +++ b/src/tool_setopt.c @@ -216,7 +216,7 @@ static char *c_escape(const char *str, curl_off_t len) result = curlx_dyn_addf(&escaped, /* Octal escape to avoid >2 digit hex. */ (len > 1 && ISXDIGIT(s[1])) ? - "\\%03o" : "\\x%02x", + "\\%03o" : "\\x%02x", (unsigned int)*(const unsigned char *)s); } } @@ -235,14 +235,14 @@ static char *c_escape(const char *str, curl_off_t len) CURLcode tool_setopt_enum(CURL *curl, const char *name, CURLoption tag, const struct NameValue *nvlist, long lval) { - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; bool skip = FALSE; - ret = curl_easy_setopt(curl, tag, lval); + result = curl_easy_setopt(curl, tag, lval); if(!lval) skip = TRUE; - if(global->libcurl && !skip && !ret) { + if(global->libcurl && !skip && !result) { /* we only use this for real if --libcurl was used */ const struct NameValue *nv = NULL; for(nv = nvlist; nv->name; nv++) { @@ -253,34 +253,34 @@ CURLcode tool_setopt_enum(CURL *curl, const char *name, CURLoption tag, /* If no definition was found, output an explicit value. * This could happen if new values are defined and used * but the NameValue list is not updated. */ - ret = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, %ldL);", - name, lval); - } - else { - ret = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, (long)%s);", - name, nv->name); + result = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, %ldL);", + name, lval); } + else + result = + easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, (long)%s);", + name, nv->name); } #ifdef DEBUGBUILD - if(ret) - warnf("option %s returned error (%d)", name, (int)ret); + if(result) + warnf("option %s returned error (%d)", name, (int)result); #endif - return ret; + return result; } /* setopt wrapper for CURLOPT_SSLVERSION */ CURLcode tool_setopt_SSLVERSION(CURL *curl, const char *name, CURLoption tag, long lval) { - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; bool skip = FALSE; - ret = curl_easy_setopt(curl, tag, lval); + result = curl_easy_setopt(curl, tag, lval); if(!lval) skip = TRUE; - if(global->libcurl && !skip && !ret) { + if(global->libcurl && !skip && !result) { /* we only use this for real if --libcurl was used */ const struct NameValue *nv = NULL; const struct NameValue *nv2 = NULL; @@ -296,28 +296,28 @@ CURLcode tool_setopt_SSLVERSION(CURL *curl, const char *name, CURLoption tag, /* If no definition was found, output an explicit value. * This could happen if new values are defined and used * but the NameValue list is not updated. */ - ret = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, %ldL);", - name, lval); + result = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, %ldL);", + name, lval); } else { if(nv2->name && *nv2->name) /* if max is set */ - ret = easysrc_addf(&easysrc_code, - "curl_easy_setopt(hnd, %s, (long)(%s | %s));", - name, nv->name, nv2->name); + result = easysrc_addf(&easysrc_code, + "curl_easy_setopt(hnd, %s, (long)(%s | %s));", + name, nv->name, nv2->name); else /* without a max */ - ret = easysrc_addf(&easysrc_code, - "curl_easy_setopt(hnd, %s, (long)%s);", - name, nv->name); + result = easysrc_addf(&easysrc_code, + "curl_easy_setopt(hnd, %s, (long)%s);", + name, nv->name); } } #ifdef DEBUGBUILD - if(ret) - warnf("option %s returned error (%d)", name, (int)ret); + if(result) + warnf("option %s returned error (%d)", name, (int)result); #endif - return ret; + return result; } /* setopt wrapper for bitmasks */ @@ -326,11 +326,11 @@ CURLcode tool_setopt_bitmask(CURL *curl, const char *name, CURLoption tag, long lval) { bool skip = FALSE; - CURLcode ret = curl_easy_setopt(curl, tag, lval); + CURLcode result = curl_easy_setopt(curl, tag, lval); if(!lval) skip = TRUE; - if(global->libcurl && !skip && !ret) { + if(global->libcurl && !skip && !result) { /* we only use this for real if --libcurl was used */ char preamble[80]; unsigned long rest = (unsigned long)lval; @@ -341,9 +341,9 @@ CURLcode tool_setopt_bitmask(CURL *curl, const char *name, CURLoption tag, if((nv->value & ~rest) == 0) { /* all value flags contained in rest */ rest &= ~nv->value; /* remove bits handled here */ - ret = easysrc_addf(&easysrc_code, "%s(long)%s%s", + result = easysrc_addf(&easysrc_code, "%s(long)%s%s", preamble, nv->name, rest ? " |" : ");"); - if(!rest || ret) + if(!rest || result) break; /* handled them all */ /* replace with all spaces for continuation line */ curl_msnprintf(preamble, sizeof(preamble), "%*s", @@ -353,42 +353,43 @@ CURLcode tool_setopt_bitmask(CURL *curl, const char *name, CURLoption tag, /* If any bits have no definition, output an explicit value. * This could happen if new bits are defined and used * but the NameValue list is not updated. */ - if(rest && !ret) - ret = easysrc_addf(&easysrc_code, "%s%luUL);", preamble, rest); + if(rest && !result) + result = easysrc_addf(&easysrc_code, "%s%luUL);", preamble, rest); } - return ret; + return result; } /* Generate code for a struct curl_slist. */ static CURLcode libcurl_generate_slist(struct curl_slist *slist, int *slistno) { - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; /* May need several slist variables, so invent name */ *slistno = ++easysrc_slist_count; - ret = easysrc_addf(&easysrc_decl, "struct curl_slist *slist%d;", *slistno); - if(!ret) - ret = easysrc_addf(&easysrc_data, "slist%d = NULL;", *slistno); - if(!ret) - ret = easysrc_addf(&easysrc_clean, "curl_slist_free_all(slist%d);", - *slistno); - if(!ret) - ret = easysrc_addf(&easysrc_clean, "slist%d = NULL;", *slistno); - if(ret) - return ret; - for(; slist && !ret; slist = slist->next) { + result = easysrc_addf(&easysrc_decl, "struct curl_slist *slist%d;", + *slistno); + if(!result) + result = easysrc_addf(&easysrc_data, "slist%d = NULL;", *slistno); + if(!result) + result = easysrc_addf(&easysrc_clean, "curl_slist_free_all(slist%d);", + *slistno); + if(!result) + result = easysrc_addf(&easysrc_clean, "slist%d = NULL;", *slistno); + if(result) + return result; + for(; slist && !result; slist = slist->next) { char *escaped = c_escape(slist->data, ZERO_TERMINATED); if(!escaped) return CURLE_OUT_OF_MEMORY; - ret = easysrc_addf(&easysrc_data, - "slist%d = curl_slist_append(slist%d, \"%s\");", - *slistno, *slistno, escaped); + result = easysrc_addf(&easysrc_data, + "slist%d = curl_slist_append(slist%d, \"%s\");", + *slistno, *slistno, escaped); curlx_free(escaped); } - return ret; + return result; } static CURLcode libcurl_generate_mime(CURL *curl, @@ -402,39 +403,40 @@ static CURLcode libcurl_generate_mime_part(CURL *curl, struct tool_mime *part, int mimeno) { - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; int submimeno = 0; const char *data = NULL; const char *filename = part->filename; /* Parts are linked in reverse order. */ if(part->prev) - ret = libcurl_generate_mime_part(curl, config, part->prev, mimeno); + result = libcurl_generate_mime_part(curl, config, part->prev, mimeno); /* Create the part. */ - if(!ret) - ret = easysrc_addf(&easysrc_code, "part%d = curl_mime_addpart(mime%d);", - mimeno, mimeno); - if(ret) - return ret; + if(!result) + result = easysrc_addf(&easysrc_code, "part%d = curl_mime_addpart(mime%d);", + mimeno, mimeno); + if(result) + return result; switch(part->kind) { case TOOLMIME_PARTS: - ret = libcurl_generate_mime(curl, config, part, &submimeno); - if(!ret) { - ret = easysrc_addf(&easysrc_code, "curl_mime_subparts(part%d, mime%d);", - mimeno, submimeno); - if(!ret) + result = libcurl_generate_mime(curl, config, part, &submimeno); + if(!result) { + result = + easysrc_addf(&easysrc_code, "curl_mime_subparts(part%d, mime%d);", + mimeno, submimeno); + if(!result) /* Avoid freeing in CLEAN. */ - ret = easysrc_addf(&easysrc_code, "mime%d = NULL;", submimeno); + result = easysrc_addf(&easysrc_code, "mime%d = NULL;", submimeno); } break; case TOOLMIME_DATA: data = part->data; - if(!ret) { + if(!result) { char *escaped = c_escape(data, ZERO_TERMINATED); - ret = + result = easysrc_addf(&easysrc_code, "curl_mime_data(part%d, \"%s\", CURL_ZERO_TERMINATED);", mimeno, escaped); @@ -445,11 +447,12 @@ static CURLcode libcurl_generate_mime_part(CURL *curl, case TOOLMIME_FILE: case TOOLMIME_FILEDATA: { char *escaped = c_escape(part->data, ZERO_TERMINATED); - ret = easysrc_addf(&easysrc_code, - "curl_mime_filedata(part%d, \"%s\");", mimeno, escaped); - if(part->kind == TOOLMIME_FILEDATA && !filename && !ret) { - ret = easysrc_addf(&easysrc_code, - "curl_mime_filename(part%d, NULL);", mimeno); + result = + easysrc_addf(&easysrc_code, + "curl_mime_filedata(part%d, \"%s\");", mimeno, escaped); + if(part->kind == TOOLMIME_FILEDATA && !filename && !result) { + result = easysrc_addf(&easysrc_code, + "curl_mime_filename(part%d, NULL);", mimeno); } curlx_free(escaped); break; @@ -461,59 +464,59 @@ static CURLcode libcurl_generate_mime_part(CURL *curl, FALLTHROUGH(); case TOOLMIME_STDINDATA: /* Can only be reading stdin in the current context. */ - ret = easysrc_addf(&easysrc_code, "curl_mime_data_cb(part%d, -1, " - "(curl_read_callback) fread, \\", mimeno); - if(!ret) - ret = easysrc_addf(&easysrc_code, " " - "(curl_seek_callback) fseek, NULL, stdin);"); + result = easysrc_addf(&easysrc_code, "curl_mime_data_cb(part%d, -1, " + "(curl_read_callback) fread, \\", mimeno); + if(!result) + result = easysrc_addf(&easysrc_code, " " + "(curl_seek_callback) fseek, NULL, stdin);"); break; default: /* Other cases not possible in this context. */ break; } - if(!ret && part->encoder) { + if(!result && part->encoder) { char *escaped = c_escape(part->encoder, ZERO_TERMINATED); - ret = easysrc_addf(&easysrc_code, "curl_mime_encoder(part%d, \"%s\");", - mimeno, escaped); + result = easysrc_addf(&easysrc_code, "curl_mime_encoder(part%d, \"%s\");", + mimeno, escaped); curlx_free(escaped); } - if(!ret && filename) { + if(!result && filename) { char *escaped = c_escape(filename, ZERO_TERMINATED); - ret = easysrc_addf(&easysrc_code, "curl_mime_filename(part%d, \"%s\");", - mimeno, escaped); + result = easysrc_addf(&easysrc_code, "curl_mime_filename(part%d, \"%s\");", + mimeno, escaped); curlx_free(escaped); } - if(!ret && part->name) { + if(!result && part->name) { char *escaped = c_escape(part->name, ZERO_TERMINATED); - ret = easysrc_addf(&easysrc_code, "curl_mime_name(part%d, \"%s\");", - mimeno, escaped); + result = easysrc_addf(&easysrc_code, "curl_mime_name(part%d, \"%s\");", + mimeno, escaped); curlx_free(escaped); } - if(!ret && part->type) { + if(!result && part->type) { char *escaped = c_escape(part->type, ZERO_TERMINATED); - ret = easysrc_addf(&easysrc_code, "curl_mime_type(part%d, \"%s\");", - mimeno, escaped); + result = easysrc_addf(&easysrc_code, "curl_mime_type(part%d, \"%s\");", + mimeno, escaped); curlx_free(escaped); } - if(!ret && part->headers) { + if(!result && part->headers) { int slistno; - ret = libcurl_generate_slist(part->headers, &slistno); - if(!ret) { - ret = easysrc_addf(&easysrc_code, - "curl_mime_headers(part%d, slist%d, 1);", - mimeno, slistno); - if(!ret) - ret = easysrc_addf(&easysrc_code, "slist%d = NULL;", slistno); + result = libcurl_generate_slist(part->headers, &slistno); + if(!result) { + result = easysrc_addf(&easysrc_code, + "curl_mime_headers(part%d, slist%d, 1);", + mimeno, slistno); + if(!result) + result = easysrc_addf(&easysrc_code, "slist%d = NULL;", slistno); } } - return ret; + return result; } /* Wrapper to generate source code for a mime structure. */ @@ -522,29 +525,29 @@ static CURLcode libcurl_generate_mime(CURL *curl, struct tool_mime *toolmime, int *mimeno) { - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; /* May need several mime variables, so invent name. */ *mimeno = ++easysrc_mime_count; - ret = easysrc_addf(&easysrc_decl, "curl_mime *mime%d;", *mimeno); - if(!ret) - ret = easysrc_addf(&easysrc_data, "mime%d = NULL;", *mimeno); - if(!ret) - ret = easysrc_addf(&easysrc_code, "mime%d = curl_mime_init(hnd);", - *mimeno); - if(!ret) - ret = easysrc_addf(&easysrc_clean, "curl_mime_free(mime%d);", *mimeno); - if(!ret) - ret = easysrc_addf(&easysrc_clean, "mime%d = NULL;", *mimeno); - - if(toolmime->subparts && !ret) { - ret = easysrc_addf(&easysrc_decl, "curl_mimepart *part%d;", *mimeno); - if(!ret) - ret = libcurl_generate_mime_part(curl, config, - toolmime->subparts, *mimeno); + result = easysrc_addf(&easysrc_decl, "curl_mime *mime%d;", *mimeno); + if(!result) + result = easysrc_addf(&easysrc_data, "mime%d = NULL;", *mimeno); + if(!result) + result = easysrc_addf(&easysrc_code, "mime%d = curl_mime_init(hnd);", + *mimeno); + if(!result) + result = easysrc_addf(&easysrc_clean, "curl_mime_free(mime%d);", *mimeno); + if(!result) + result = easysrc_addf(&easysrc_clean, "mime%d = NULL;", *mimeno); + + if(toolmime->subparts && !result) { + result = easysrc_addf(&easysrc_decl, "curl_mimepart *part%d;", *mimeno); + if(!result) + result = libcurl_generate_mime_part(curl, config, + toolmime->subparts, *mimeno); } - return ret; + return result; } /* setopt wrapper for CURLOPT_MIMEPOST */ @@ -552,38 +555,40 @@ CURLcode tool_setopt_mimepost(CURL *curl, struct OperationConfig *config, const char *name, CURLoption tag, curl_mime *mimepost) { - CURLcode ret = curl_easy_setopt(curl, tag, mimepost); + CURLcode result = curl_easy_setopt(curl, tag, mimepost); int mimeno = 0; - if(!ret && global->libcurl) { - ret = libcurl_generate_mime(curl, config, config->mimeroot, &mimeno); + if(!result && global->libcurl) { + result = libcurl_generate_mime(curl, config, config->mimeroot, &mimeno); - if(!ret) - ret = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, mime%d);", - name, mimeno); + if(!result) + result = + easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, mime%d);", + name, mimeno); } - return ret; + return result; } /* setopt wrapper for curl_slist options */ CURLcode tool_setopt_slist(CURL *curl, const char *name, CURLoption tag, struct curl_slist *list) { - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; - ret = curl_easy_setopt(curl, tag, list); + result = curl_easy_setopt(curl, tag, list); - if(global->libcurl && list && !ret) { + if(global->libcurl && list && !result) { int i; - ret = libcurl_generate_slist(list, &i); - if(!ret) - ret = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, slist%d);", - name, i); + result = libcurl_generate_slist(list, &i); + if(!result) + result = + easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, slist%d);", + name, i); } - return ret; + return result; } /* options that set long */ @@ -592,7 +597,7 @@ CURLcode tool_setopt_long(CURL *curl, const char *name, CURLoption tag, { long defval = 0L; const struct NameValue *nv = NULL; - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; DEBUGASSERT(tag < CURLOPTTYPE_OBJECTPOINT); for(nv = setopt_nv_CURLNONZERODEFAULTS; nv->name; nv++) { @@ -602,30 +607,31 @@ CURLcode tool_setopt_long(CURL *curl, const char *name, CURLoption tag, } } - ret = curl_easy_setopt(curl, tag, lval); - if((lval != defval) && global->libcurl && !ret) { + result = curl_easy_setopt(curl, tag, lval); + if((lval != defval) && global->libcurl && !result) { /* we only use this for real if --libcurl was used */ - ret = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, %ldL);", - name, lval); + result = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, %ldL);", + name, lval); } - return ret; + return result; } /* options that set curl_off_t */ CURLcode tool_setopt_offt(CURL *curl, const char *name, CURLoption tag, curl_off_t lval) { - CURLcode ret = CURLE_OK; + CURLcode result = CURLE_OK; DEBUGASSERT((tag >= CURLOPTTYPE_OFF_T) && (tag < CURLOPTTYPE_BLOB)); - ret = curl_easy_setopt(curl, tag, lval); - if(global->libcurl && !ret && lval) { + result = curl_easy_setopt(curl, tag, lval); + if(global->libcurl && !result && lval) { /* we only use this for real if --libcurl was used */ - ret = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, (curl_off_t)%" - CURL_FORMAT_CURL_OFF_T ");", name, lval); + result = + easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, (curl_off_t)%" + CURL_FORMAT_CURL_OFF_T ");", name, lval); } - return ret; + return result; } /* setopt wrapper for setting object and function pointers */ diff --git a/src/tool_ssls.c b/src/tool_ssls.c index 4937031d6b..22f2571126 100644 --- a/src/tool_ssls.c +++ b/src/tool_ssls.c @@ -61,7 +61,7 @@ CURLcode tool_ssls_load(struct OperationConfig *config, unsigned char *shmac = NULL, *sdata = NULL; char *c, *line, *end; size_t shmac_len, sdata_len; - CURLcode r = CURLE_OK; + CURLcode result = CURLE_OK; int i, imported; bool error = FALSE; @@ -72,8 +72,8 @@ CURLcode tool_ssls_load(struct OperationConfig *config, goto out; } - r = tool_ssls_easy(config, share, &easy); - if(r) + result = tool_ssls_easy(config, share, &easy); + if(result) goto out; i = imported = 0; @@ -89,8 +89,8 @@ CURLcode tool_ssls_load(struct OperationConfig *config, continue; } *c = '\0'; - r = curlx_base64_decode(line, &shmac, &shmac_len); - if(r) { + result = curlx_base64_decode(line, &shmac, &shmac_len); + if(result) { warnf("invalid shmax base64 encoding in line %d", i); continue; } @@ -100,23 +100,24 @@ CURLcode tool_ssls_load(struct OperationConfig *config, *end = '\0'; --end; } - r = curlx_base64_decode(line, &sdata, &sdata_len); - if(r) { + result = curlx_base64_decode(line, &sdata, &sdata_len); + if(result) { warnf("invalid sdata base64 encoding in line %d: %s", i, line); continue; } - r = curl_easy_ssls_import(easy, NULL, shmac, shmac_len, sdata, sdata_len); - if(r) { - warnf("import of session from line %d rejected(%d)", i, r); + result = curl_easy_ssls_import(easy, NULL, shmac, shmac_len, sdata, + sdata_len); + if(result) { + warnf("import of session from line %d rejected(%d)", i, result); continue; } ++imported; } if(error) - r = CURLE_FAILED_INIT; + result = CURLE_FAILED_INIT; else - r = CURLE_OK; + result = CURLE_OK; out: if(easy) @@ -126,7 +127,7 @@ out: curlx_dyn_free(&buf); curlx_free(shmac); curlx_free(sdata); - return r; + return result; } struct tool_ssls_ctx { @@ -144,7 +145,7 @@ static CURLcode tool_ssls_exp(CURL *easy, void *userptr, struct tool_ssls_ctx *ctx = userptr; char *enc = NULL; size_t enc_len; - CURLcode r; + CURLcode result; (void)easy; (void)valid_until; @@ -156,30 +157,31 @@ static CURLcode tool_ssls_exp(CURL *easy, void *userptr, "# This file was generated by libcurl! Edit at your own risk.\n", ctx->fp); - r = curlx_base64_encode(shmac, shmac_len, &enc, &enc_len); - if(r) + result = curlx_base64_encode(shmac, shmac_len, &enc, &enc_len); + if(result) goto out; - r = CURLE_WRITE_ERROR; + result = CURLE_WRITE_ERROR; if(enc_len != fwrite(enc, 1, enc_len, ctx->fp)) goto out; if(EOF == fputc(':', ctx->fp)) goto out; tool_safefree(enc); - r = curlx_base64_encode(sdata, sdata_len, &enc, &enc_len); - if(r) + result = curlx_base64_encode(sdata, sdata_len, &enc, &enc_len); + if(result) goto out; - r = CURLE_WRITE_ERROR; + result = CURLE_WRITE_ERROR; if(enc_len != fwrite(enc, 1, enc_len, ctx->fp)) goto out; if(EOF == fputc('\n', ctx->fp)) goto out; - r = CURLE_OK; + result = CURLE_OK; ctx->exported++; out: - if(r) - warnf("Warning: error saving SSL session for '%s': %d", session_key, r); + if(result) + warnf("Warning: error saving SSL session for '%s': %d", session_key, + result); curlx_free(enc); - return r; + return result; } CURLcode tool_ssls_save(struct OperationConfig *config, @@ -187,7 +189,7 @@ CURLcode tool_ssls_save(struct OperationConfig *config, { struct tool_ssls_ctx ctx; CURL *easy = NULL; - CURLcode r = CURLE_OK; + CURLcode result = CURLE_OK; ctx.exported = 0; ctx.fp = curlx_fopen(filename, FOPEN_WRITETEXT); @@ -196,16 +198,16 @@ CURLcode tool_ssls_save(struct OperationConfig *config, goto out; } - r = tool_ssls_easy(config, share, &easy); - if(r) + result = tool_ssls_easy(config, share, &easy); + if(result) goto out; - r = curl_easy_ssls_export(easy, tool_ssls_exp, &ctx); + result = curl_easy_ssls_export(easy, tool_ssls_exp, &ctx); out: if(easy) curl_easy_cleanup(easy); if(ctx.fp) curlx_fclose(ctx.fp); - return r; + return result; } diff --git a/src/tool_urlglob.c b/src/tool_urlglob.c index 4ab37c935f..ba1059659a 100644 --- a/src/tool_urlglob.c +++ b/src/tool_urlglob.c @@ -410,20 +410,20 @@ static CURLcode glob_parse(struct URLGlob *glob, const char *pattern, /* processes a literal string component of a URL special characters '{' and '[' branch to set/range processing functions */ - CURLcode res = CURLE_OK; + CURLcode result = CURLE_OK; int globindex = 0; /* count "actual" globs */ *amount = 1; - while(*pattern && !res) { + while(*pattern && !result) { while(*pattern && *pattern != '{') { if(*pattern == '[') { /* skip over IPv6 literals and [] */ size_t skip = 0; bool ipv6; - res = peek_ipv6(pattern, &skip, &ipv6); - if(res) - return res; + result = peek_ipv6(pattern, &skip, &ipv6); + if(result) + return result; if(!ipv6 && (pattern[1] == ']')) skip = 2; if(skip) { @@ -454,10 +454,10 @@ static CURLcode glob_parse(struct URLGlob *glob, const char *pattern, } if(curlx_dyn_len(&glob->buf)) { /* we got a literal string, add it as a single-item list */ - res = glob_fixed(glob, curlx_dyn_ptr(&glob->buf), + result = glob_fixed(glob, curlx_dyn_ptr(&glob->buf), curlx_dyn_len(&glob->buf)); - if(!res) - res = add_glob(glob, pos); + if(!result) + result = add_glob(glob, pos); curlx_dyn_reset(&glob->buf); } else { @@ -467,21 +467,21 @@ static CURLcode glob_parse(struct URLGlob *glob, const char *pattern, /* process set pattern */ pattern++; pos++; - res = glob_set(glob, &pattern, &pos, amount, globindex++); - if(!res) - res = add_glob(glob, pos); + result = glob_set(glob, &pattern, &pos, amount, globindex++); + if(!result) + result = add_glob(glob, pos); } else if(*pattern == '[') { /* process range pattern */ pattern++; pos++; - res = glob_range(glob, &pattern, &pos, amount, globindex++); - if(!res) - res = add_glob(glob, pos); + result = glob_range(glob, &pattern, &pos, amount, globindex++); + if(!result) + result = add_glob(glob, pos); } } } - return res; + return result; } bool glob_inuse(struct URLGlob *glob) @@ -497,7 +497,7 @@ CURLcode glob_url(struct URLGlob *glob, const char *url, curl_off_t *urlnum, * as the specified URL! */ curl_off_t amount = 0; - CURLcode res; + CURLcode result; memset(glob, 0, sizeof(struct URLGlob)); curlx_dyn_init(&glob->buf, MAX_CONFIG_LINE_LENGTH); @@ -506,8 +506,8 @@ CURLcode glob_url(struct URLGlob *glob, const char *url, curl_off_t *urlnum, return CURLE_OUT_OF_MEMORY; glob->palloc = 2; - res = glob_parse(glob, url, 1, &amount); - if(res) { + result = glob_parse(glob, url, 1, &amount); + if(result) { if(error && glob->error) { char text[512]; const char *t; @@ -521,10 +521,10 @@ CURLcode glob_url(struct URLGlob *glob, const char *url, curl_off_t *urlnum, t = glob->error; /* send error description to the error-stream */ - curl_mfprintf(error, "curl: (%d) %s\n", res, t); + curl_mfprintf(error, "curl: (%d) %s\n", result, t); } *urlnum = 1; - return res; + return result; } *urlnum = amount; return CURLE_OK;