tidy-up: miscellaneous

- INSTALL-CMAKE.md: add missing periods, text fixes.
- md4, md5: sync variables names.
- curl_trc: sync an argument type.
- docs/examples: sync debug/trace function copies, constify, tidy-ups.
- replace commented code with `#if 0`.
- drop redundant parenthesis (macro values, `return`, around single
  variables, function calls).
- fix indentation, apply clang-format in places.

Closes #20481
This commit is contained in:
Viktor Szakats 2026-01-23 12:59:42 +01:00
parent ca5efd02b6
commit 3003c32cb2
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
62 changed files with 291 additions and 281 deletions

View file

@ -229,8 +229,7 @@ static int is_ipv4_mapped_ipv6_address(int family, void *netaddr)
}
#endif /* AF_INET6 */
static curl_socket_t opensocket(void *clientp,
curlsocktype purpose,
static curl_socket_t opensocket(void *clientp, curlsocktype purpose,
struct curl_sockaddr *address)
{
/* filter the address */

View file

@ -33,7 +33,7 @@ struct data {
char trace_ascii; /* 1 or 0 */
};
static void dump(const char *text, FILE *stream, unsigned char *ptr,
static void dump(const char *text, const unsigned char *ptr,
size_t size, char nohex)
{
size_t i;
@ -45,20 +45,20 @@ static void dump(const char *text, FILE *stream, unsigned char *ptr,
/* without the hex output, we can fit more on screen */
width = 0x40;
fprintf(stream, "%s, %10.10lu bytes (0x%8.8lx)\n",
fprintf(stderr, "%s, %10.10lu bytes (0x%8.8lx)\n",
text, (unsigned long)size, (unsigned long)size);
for(i = 0; i < size; i += width) {
fprintf(stream, "%4.4lx: ", (unsigned long)i);
fprintf(stderr, "%4.4lx: ", (unsigned long)i);
if(!nohex) {
/* hex not disabled, show it */
for(c = 0; c < width; c++)
if(i + c < size)
fprintf(stream, "%02x ", ptr[i + c]);
fprintf(stderr, "%02x ", ptr[i + c]);
else
fputs(" ", stream);
fputs(" ", stderr);
}
for(c = 0; (c < width) && (i + c < size); c++) {
@ -68,7 +68,7 @@ static void dump(const char *text, FILE *stream, unsigned char *ptr,
i += (c + 2 - width);
break;
}
fprintf(stream, "%c",
fprintf(stderr, "%c",
(ptr[i + c] >= 0x20) && (ptr[i + c] < 0x80) ? ptr[i + c] : '.');
/* check again for 0D0A, to avoid an extra \n if it is at width */
if(nohex && (i + c + 2 < size) && ptr[i + c + 1] == 0x0D &&
@ -77,9 +77,8 @@ static void dump(const char *text, FILE *stream, unsigned char *ptr,
break;
}
}
fputc('\n', stream); /* newline */
fputc('\n', stderr); /* newline */
}
fflush(stream);
}
static int my_trace(CURL *curl, curl_infotype type,
@ -115,7 +114,7 @@ static int my_trace(CURL *curl, curl_infotype type,
return 0;
}
dump(text, stderr, (unsigned char *)data, size, config->trace_ascii);
dump(text, (const unsigned char *)data, size, config->trace_ascii);
return 0;
}

View file

@ -133,7 +133,9 @@ int main(int argc, char **argv)
curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
/* curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); */
#if 0
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
/* set a URL containing wildcard pattern (only in the last part) */
if(argc == 2)

View file

@ -47,7 +47,8 @@ static size_t throw_away(void *ptr, size_t size, size_t nmemb, void *data)
int main(void)
{
char ftpurl[] = "ftp://ftp.example.com/gnu/binutils/binutils-2.19.1.tar.bz2";
static const char ftpurl[] =
"ftp://ftp.example.com/gnu/binutils/binutils-2.19.1.tar.bz2";
CURL *curl;
CURLcode result;
long filetime = -1;
@ -68,7 +69,9 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, throw_away);
curl_easy_setopt(curl, CURLOPT_HEADER, 0L);
/* Switch on full protocol/debug output */
/* curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); */
#if 0
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
result = curl_easy_perform(curl);

View file

@ -158,8 +158,8 @@ static gboolean timer_cb(gpointer data)
struct GlobalInfo *g = (struct GlobalInfo *)data;
CURLMcode mresult;
mresult = curl_multi_socket_action(g->multi,
CURL_SOCKET_TIMEOUT, 0, &g->still_running);
mresult = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0,
&g->still_running);
mcode_or_die("timer_cb: curl_multi_socket_action", mresult);
check_multi_info(g);
return FALSE;
@ -360,7 +360,7 @@ static gboolean fifo_cb(GIOChannel *ch, GIOCondition condition, gpointer data)
}
else {
buf = g_malloc(BUF_SIZE + 1);
while(TRUE) {
for(;;) {
buf[BUF_SIZE] = '\0';
g_io_channel_read_chars(ch, buf, BUF_SIZE, &len, &err);
if(len) {

View file

@ -220,8 +220,8 @@ static void timer_cb(int fd, short kind, void *userp)
(void)fd;
(void)kind;
mresult = curl_multi_socket_action(g->multi,
CURL_SOCKET_TIMEOUT, 0, &g->still_running);
mresult = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0,
&g->still_running);
mcode_or_die("timer_cb: curl_multi_socket_action", mresult);
check_multi_info(g);
}

View file

@ -55,7 +55,7 @@ struct transfer {
int num;
};
static void dump(const char *text, int num, unsigned char *ptr,
static void dump(const char *text, int num, const unsigned char *ptr,
size_t size, char nohex)
{
size_t i;
@ -136,7 +136,7 @@ static int my_trace(CURL *curl, curl_infotype type,
return 0;
}
dump(text, num, (unsigned char *)data, size, 1);
dump(text, num, (const unsigned char *)data, size, 1);
return 0;
}

View file

@ -47,7 +47,8 @@
static FILE *out_download;
static void dump(const char *text, unsigned char *ptr, size_t size, char nohex)
static void dump(const char *text, const unsigned char *ptr,
size_t size, char nohex)
{
size_t i;
size_t c;
@ -126,7 +127,7 @@ static int my_trace(CURL *curl, curl_infotype type,
return 0;
}
dump(text, (unsigned char *)data, size, 1);
dump(text, (const unsigned char *)data, size, 1);
return 0;
}

View file

@ -73,7 +73,7 @@ static int my_gettimeofday(struct timeval *tp, void *tzp)
(void)tzp;
if(tp) {
/* Offset between 1601-01-01 and 1970-01-01 in 100 nanosec units */
#define WIN32_FT_OFFSET (116444736000000000)
#define WIN32_FT_OFFSET 116444736000000000
union {
CURL_TYPEOF_CURL_OFF_T ns100; /* time since 1 Jan 1601 in 100ns units */
FILETIME ft;
@ -191,7 +191,7 @@ static int my_trace(CURL *curl, curl_infotype type,
return 0;
}
dump(text, num, (unsigned char *)data, size, 1);
dump(text, num, (const unsigned char *)data, size, 1);
return 0;
}

View file

@ -30,9 +30,7 @@
#include <curl/curl.h>
#define TRUE 1
static void dump(const char *text, FILE *stream, const unsigned char *ptr,
static void dump(const char *text, const unsigned char *ptr,
size_t size, char nohex)
{
size_t i;
@ -44,20 +42,20 @@ static void dump(const char *text, FILE *stream, const unsigned char *ptr,
/* without the hex output, we can fit more on screen */
width = 0x40;
fprintf(stream, "%s, %10.10lu bytes (0x%8.8lx)\n",
fprintf(stderr, "%s, %10.10lu bytes (0x%8.8lx)\n",
text, (unsigned long)size, (unsigned long)size);
for(i = 0; i < size; i += width) {
fprintf(stream, "%4.4lx: ", (unsigned long)i);
fprintf(stderr, "%4.4lx: ", (unsigned long)i);
if(!nohex) {
/* hex not disabled, show it */
for(c = 0; c < width; c++)
if(i + c < size)
fprintf(stream, "%02x ", ptr[i + c]);
fprintf(stderr, "%02x ", ptr[i + c]);
else
fputs(" ", stream);
fputs(" ", stderr);
}
for(c = 0; (c < width) && (i + c < size); c++) {
@ -67,7 +65,7 @@ static void dump(const char *text, FILE *stream, const unsigned char *ptr,
i += (c + 2 - width);
break;
}
fprintf(stream, "%c",
fprintf(stderr, "%c",
(ptr[i + c] >= 0x20) && (ptr[i + c] < 0x80) ? ptr[i + c] : '.');
/* check again for 0D0A, to avoid an extra \n if it is at width */
if(nohex && (i + c + 2 < size) && ptr[i + c + 1] == 0x0D &&
@ -76,14 +74,12 @@ static void dump(const char *text, FILE *stream, const unsigned char *ptr,
break;
}
}
fputc('\n', stream); /* newline */
fputc('\n', stderr); /* newline */
}
fflush(stream);
}
static int my_trace(CURL *curl, curl_infotype type,
unsigned char *data, size_t size,
void *userp)
char *data, size_t size, void *userp)
{
const char *text;
@ -110,7 +106,7 @@ static int my_trace(CURL *curl, curl_infotype type,
return 0;
}
dump(text, stderr, data, size, TRUE);
dump(text, (const unsigned char *)data, size, 1);
return 0;
}

View file

@ -125,7 +125,7 @@ int main(void)
do {
nsent = 0;
result = curl_easy_send(curl, request + nsent_total,
request_len - nsent_total, &nsent);
request_len - nsent_total, &nsent);
nsent_total += nsent;
if(result == CURLE_AGAIN && !wait_on_socket(sockfd, 0, 60000L)) {

View file

@ -72,7 +72,7 @@ static curl_off_t sftpGetRemoteFileSize(const char *i_remoteFile)
result = curl_easy_perform(curl);
if(CURLE_OK == result) {
result = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T,
&remoteFileSizeByte);
&remoteFileSizeByte);
if(result)
return -1;
printf("filesize: %" CURL_FORMAT_CURL_OFF_T "\n", remoteFileSizeByte);

View file

@ -152,7 +152,9 @@ static void *create_thread(void *progress_bar)
gtk_widget_destroy(progress_bar);
/* [Un]Comment this out to kill the program rather than pushing close. */
/* gtk_main_quit(); */
#if 0
gtk_main_quit();
#endif
return NULL;
}