License: curl
# checksrc control files
-Files: lib/.checksrc docs/examples/.checksrc tests/libtest/.checksrc
+Files: lib/.checksrc src/.checksrc docs/examples/.checksrc tests/libtest/.checksrc
Copyright: Daniel Stenberg, <daniel@haxx.se>, et al.
License: curl
- `STRERROR`: use of banned function strerror()
+- `STDERR`: use of banned variable `stderr`
+
## Ignore certain warnings
Due to the nature of the source code and the flaws of the `checksrc` tool,
my %warnings_extended = (
'COPYRIGHTYEAR' => 'copyright year incorrect',
'STRERROR', => 'strerror() detected',
+ 'STDERR', => 'stderr detected',
);
my %warnings = (
}
}
}
+ if($warnings{"STDERR"}) {
+ # scan for use of banned stderr. This is not a BANNEDFUNC to
+ # allow for individual enable/disable of this warning.
+ if($l =~ /^([^\"-]*\W)(stderr)[^\"_]/x) {
+ if($1 !~ /^ *\#/) {
+ # skip preprocessor lines
+ checkwarn("STDERR",
+ $line, length($1), $file, $ol,
+ "use of $2 is banned (use tool_stderr instead)");
+ }
+ }
+ }
# scan for use of snprintf for curl-internals reasons
if($l =~ /^(.*\W)(v?snprintf)\s*\(/x) {
checkwarn("SNPRINTF",
--- /dev/null
+enable STDERR
set(CURLX_CFILES ${CURLTOOL_LIBCURL_CFILES})
endif()
-# Compile this source separately to avoid having `stderr` overridden in this
-# file. Necessary for successfully initializing stderr in unity builds.
-# (Not necessary for the libcurltool target.)
-set_source_files_properties(tool_stderr.c PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
-
add_executable(
${EXE_NAME}
${CURL_CFILES} ${CURLX_CFILES} ${CURL_HFILES}
{
struct OperationConfig *operation = userdata;
struct GlobalConfig *config = operation->global;
- FILE *output = stderr;
+ FILE *output = tool_stderr;
const char *text;
struct timeval tv;
char timebuf[20];
config->trace_stream = stdout;
else if(!strcmp("%", config->trace_dump))
/* Ok, this is somewhat hackish but we do it undocumented for now */
- config->trace_stream = stderr;
+ config->trace_stream = tool_stderr;
else {
config->trace_stream = fopen(config->trace_dump, FOPEN_WRITETEXT);
config->trace_fopened = TRUE;
to stderr or stdout, we don't display the alert about the data not
being shown as the data _is_ shown then just not via this
function */
- if(!config->isatty || ((output != stderr) && (output != stdout))) {
+ if(!config->isatty ||
+ ((output != tool_stderr) && (output != stdout))) {
if(!newl)
log_line_start(output, timebuf, idsbuf, type);
fprintf(output, "[%zu bytes data]\n", size);
else if(bar->width > MAX_BARLENGTH)
bar->width = MAX_BARLENGTH;
- bar->out = stderr;
+ bar->out = tool_stderr;
bar->tick = 150;
bar->barmove = 1;
}
const char *reason = param2text(result);
if(orig_opt && strcmp(":", orig_opt))
- helpf(stderr, "option %s: %s", orig_opt, reason);
+ helpf(tool_stderr, "option %s: %s", orig_opt, reason);
else
- helpf(stderr, "%s", reason);
+ helpf(tool_stderr, "%s", reason);
}
curlx_unicodefree(orig_opt);
char *getpass_r(const char *prompt, char *buffer, size_t buflen)
{
size_t i;
- fputs(prompt, stderr);
+ fputs(prompt, tool_stderr);
for(i = 0; i < buflen; i++) {
buffer[i] = (char)getch();
i = i - (i >= 1 ? 2 : 1);
}
/* since echo is disabled, print a newline */
- fputs("\n", stderr);
+ fputs("\n", tool_stderr);
/* if user didn't hit ENTER, terminate buffer */
if(i == buflen)
buffer[buflen-1] = '\0';
disabled = ttyecho(FALSE, fd); /* disable terminal echo */
- fputs(prompt, stderr);
+ fputs(prompt, tool_stderr);
nread = read(fd, password, buflen);
if(nread > 0)
password[--nread] = '\0'; /* null-terminate where enter is stored */
if(disabled) {
/* if echo actually was disabled, add a newline */
- fputs("\n", stderr);
+ fputs("\n", tool_stderr);
(void)ttyecho(TRUE, fd); /* enable echo */
}
{
const char *const *builtin;
if(is_debug())
- fprintf(stderr, "WARNING: this libcurl is Debug-enabled, "
+ fprintf(tool_stderr, "WARNING: this libcurl is Debug-enabled, "
"do not use in production\n\n");
printf(CURL_ID "%s\n", curl_version());
#endif
#ifndef STDERR_FILENO
-# define STDERR_FILENO fileno(stderr)
+# define STDERR_FILENO fileno(tool_stderr)
#endif
#endif /* HEADER_CURL_TOOL_MAIN_H */
ptr = print_buffer;
while(len > 0) {
- fputs(prefix, stderr);
+ fputs(prefix, tool_stderr);
if(len > width) {
size_t cut = width-1;
max text width then! */
cut = width-1;
- (void)fwrite(ptr, cut + 1, 1, stderr);
- fputs("\n", stderr);
+ (void)fwrite(ptr, cut + 1, 1, tool_stderr);
+ fputs("\n", tool_stderr);
ptr += cut + 1; /* skip the space too */
len -= cut + 1;
}
else {
- fputs(ptr, stderr);
- fputs("\n", stderr);
+ fputs(ptr, tool_stderr);
+ fputs("\n", tool_stderr);
len = 0;
}
}
if((per->infd == -1) || fstat(per->infd, &fileinfo))
#endif
{
- helpf(stderr, "Can't open '%s'", per->uploadfile);
+ helpf(tool_stderr, "Can't open '%s'", per->uploadfile);
if(per->infd != -1) {
close(per->infd);
per->infd = STDIN_FILENO;
if(!config->synthetic_error && result &&
(!global->silent || global->showerror)) {
const char *msg = per->errorbuffer;
- fprintf(stderr, "curl: (%d) %s\n", result,
+ fprintf(tool_stderr, "curl: (%d) %s\n", result,
(msg && msg[0]) ? msg : curl_easy_strerror(result));
if(result == CURLE_PEER_FAILED_VERIFICATION)
- fputs(CURL_CA_CERT_ERRORMSG, stderr);
+ fputs(CURL_CA_CERT_ERRORMSG, tool_stderr);
}
else if(config->failwithbody) {
/* if HTTP response >= 400, return error */
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
if(code >= 400) {
if(!global->silent || global->showerror)
- fprintf(stderr,
+ fprintf(tool_stderr,
"curl: (%d) The requested URL returned error: %ld\n",
CURLE_HTTP_RETURNED_ERROR, code);
result = CURLE_HTTP_RETURNED_ERROR;
switch(result) {
case CURLE_URL_MALFORMAT:
- helpf(stderr, "malformed URL. Visit https://curl.se/"
+ helpf(tool_stderr, "malformed URL. Visit https://curl.se/"
"docs/ipfs.html#Gateway-file-and-"
"environment-variable for more "
"information");
break;
case CURLE_FILE_COULDNT_READ_FILE:
- helpf(stderr, "IPFS automatic gateway detection "
+ helpf(tool_stderr, "IPFS automatic gateway detection "
"failure. Visit https://curl.se/docs/"
"ipfs.html#Malformed-gateway-URL for "
"more information");
break;
case CURLE_BAD_FUNCTION_ARGUMENT:
- helpf(stderr, "--ipfs-gateway argument results in "
+ helpf(tool_stderr, "--ipfs-gateway argument results in "
"malformed URL. Visit https://curl.se/"
"docs/ipfs.html#Malformed-gateway-URL "
"for more information");
/* Unless explicitly shut off */
result = glob_url(&inglob, infiles, &state->infilenum,
(!global->silent || global->showerror)?
- stderr:NULL);
+ tool_stderr:NULL);
if(result)
break;
config->state.inglob = inglob;
expressions and return total number of URLs in pattern set */
result = glob_url(&state->urls, urlnode->url, &state->urlnum,
(!global->silent || global->showerror)?
- stderr:NULL);
+ tool_stderr:NULL);
if(result)
break;
urlnum = state->urlnum;
my_setopt(curl, CURLOPT_TIMEVALUE_LARGE, config->condtime);
my_setopt_str(curl, CURLOPT_CUSTOMREQUEST, config->customrequest);
customrequest_helper(config, config->httpreq, config->customrequest);
- my_setopt(curl, CURLOPT_STDERR, stderr);
+ my_setopt(curl, CURLOPT_STDERR, tool_stderr);
/* three new ones in libcurl 7.3: */
my_setopt_str(curl, CURLOPT_INTERFACE, config->iface);
/* Check we have a url */
if(!config->url_list || !config->url_list->url) {
- helpf(stderr, "(%d) no URL specified", CURLE_FAILED_INIT);
+ helpf(tool_stderr, "(%d) no URL specified", CURLE_FAILED_INIT);
return CURLE_FAILED_INIT;
}
/* If we had no arguments then make sure a url was specified in .curlrc */
if((argc < 2) && (!global->first->url_list)) {
- helpf(stderr, NULL);
+ helpf(tool_stderr, NULL);
result = CURLE_FAILED_INIT;
}
}
*line++ = '\0'; /* null-terminate, we have a local copy of the data */
#ifdef DEBUG_CONFIG
- fprintf(stderr, "GOT: %s\n", option);
+ fprintf(tool_stderr, "GOT: %s\n", option);
#endif
/* pass spaces and separator(s) */
}
#ifdef DEBUG_CONFIG
- fprintf(stderr, "PARAM: \"%s\"\n",(param ? param : "(null)"));
+ fprintf(tool_stderr, "PARAM: \"%s\"\n",(param ? param : "(null)"));
#endif
res = getparameter(option, param, NULL, &usedarg, global, operation);
operation = global->last;
header = TRUE;
fputs("DL% UL% Dled Uled Xfers Live "
"Total Current Left Speed\n",
- stderr);
+ tool_stderr);
}
if(final || (diff > 500)) {
char time_left[10];
}
time2str(time_spent, spent);
- fprintf(stderr,
+ fprintf(tool_stderr,
"\r"
"%-3s " /* percent downloaded */
"%-3s " /* percent uploaded */
extern FILE *tool_stderr;
-#if !defined(CURL_DO_NOT_OVERRIDE_STDERR) && !defined(UNITTESTS)
-#ifdef stderr
-#undef stderr
-#endif
-#define stderr tool_stderr
-#endif
-
/*
* curl tool certainly uses libcurl's external interface.
*/
*
***************************************************************************/
-/* In this file, stdio.h's stderr macro is not overridden. */
-#define CURL_DO_NOT_OVERRIDE_STDERR
-
#include "tool_setup.h"
#include "tool_stderr.h"
#include "tool_msgs.h"
#include "memdebug.h" /* keep this as LAST include */
-/* In other tool files stderr is defined as tool_stderr by tool_setup.h */
FILE *tool_stderr;
void tool_init_stderr(void)
{
+ /* !checksrc! disable STDERR 1 */
tool_stderr = stderr;
}
/* freopen the actual stderr (stdio.h stderr) instead of tool_stderr since
the latter may be set to stdout. */
+ /* !checksrc! disable STDERR 1 */
fp = freopen(filename, FOPEN_WRITETEXT, stderr);
if(!fp) {
/* stderr may have been closed by freopen. there is nothing to be done. */
DEBUGASSERT(0);
return;
}
+ /* !checksrc! disable STDERR 1 */
tool_stderr = stderr;
}
appendlen = strlen(numbuf);
break;
default:
- fprintf(stderr, "internal error: invalid pattern type (%d)\n",
+ fprintf(tool_stderr, "internal error: invalid pattern type (%d)\n",
(int)pat->type);
curlx_dyn_free(&dyn);
return CURLE_FAILED_INIT;
if(fclose_stream)
fclose(stream);
fclose_stream = FALSE;
- stream = stderr;
+ stream = tool_stderr;
break;
case VAR_JSON:
ourWriteOutJSON(stream, variables, per, per_result);
}
}
if(!match) {
- fprintf(stderr, "curl: unknown --write-out variable: '%.*s'\n",
+ fprintf(tool_stderr,
+ "curl: unknown --write-out variable: '%.*s'\n",
(int)vlen, ptr);
}
ptr = end + 1; /* pass the end */