From: Viktor Szakats Date: Fri, 28 Nov 2025 13:19:18 +0000 (+0100) Subject: example: fix formatting nits X-Git-Tag: rc-8_18_0-1~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aad3c2e8e14317c99838e3766df6cd2ce8f3f279;p=thirdparty%2Fcurl.git example: fix formatting nits Also: - drop non-portable `__STRING()` macro use where still used. Closes #19746 --- diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index bddcd15637..22db7c5fc4 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -81,7 +81,7 @@ static const char *urls[] = { }; #define MAX_PARALLEL 10 /* number of simultaneous transfers */ -#define NUM_URLS sizeof(urls)/sizeof(char *) +#define NUM_URLS (sizeof(urls) / sizeof(char *)) static size_t write_cb(char *data, size_t n, size_t l, void *userp) { diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index eb5959ca22..247d4d0d3b 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -65,9 +65,9 @@ /* seek callback function */ static int my_seek(void *userp, curl_off_t offset, int origin) { - FILE *fp = (FILE *) userp; + FILE *fp = (FILE *)userp; - if(fseek(fp, (long) offset, origin) == -1) + if(fseek(fp, (long)offset, origin) == -1) /* could not seek */ return CURL_SEEKFUNC_CANTSEEK; @@ -128,13 +128,13 @@ int main(int argc, char **argv) curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb); /* which file to upload */ - curl_easy_setopt(curl, CURLOPT_READDATA, (void *) fp); + curl_easy_setopt(curl, CURLOPT_READDATA, (void *)fp); /* set the seek function */ curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, my_seek); /* pass the file descriptor to the seek callback as well */ - curl_easy_setopt(curl, CURLOPT_SEEKDATA, (void *) fp); + curl_easy_setopt(curl, CURLOPT_SEEKDATA, (void *)fp); /* enable "uploading" (which means PUT when doing HTTP) */ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); diff --git a/docs/examples/block_ip.c b/docs/examples/block_ip.c index ef7056dc43..bf2193a263 100644 --- a/docs/examples/block_ip.c +++ b/docs/examples/block_ip.c @@ -31,7 +31,11 @@ #ifdef __AMIGA__ #include -int main(void) { printf("Platform not supported.\n"); return 1; } +int main(void) +{ + printf("Platform not supported.\n"); + return 1; +} #else #ifdef _MSC_VER diff --git a/docs/examples/certinfo.c b/docs/examples/certinfo.c index 3176d0a1fc..e799cfc928 100644 --- a/docs/examples/certinfo.c +++ b/docs/examples/certinfo.c @@ -29,7 +29,7 @@ #include -static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream) +static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream) { (void)stream; (void)ptr; @@ -74,10 +74,8 @@ int main(void) for(slist = certinfo->certinfo[i]; slist; slist = slist->next) printf("%s\n", slist->data); - } } - } curl_easy_cleanup(curl); diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index a031380f12..0398cdf164 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -71,8 +71,7 @@ static int print_cookies(CURL *curl) return 0; } -int -main(void) +int main(void) { CURL *curl; CURLcode res; diff --git a/docs/examples/crawler.c b/docs/examples/crawler.c index 419ceab26d..9207199cdf 100644 --- a/docs/examples/crawler.c +++ b/docs/examples/crawler.c @@ -65,7 +65,7 @@ struct memory { static size_t write_cb(void *contents, size_t sz, size_t nmemb, void *ctx) { size_t realsize = sz * nmemb; - struct memory *mem = (struct memory*) ctx; + struct memory *mem = (struct memory *)ctx; char *ptr = realloc(mem->buf, mem->size + realsize); if(!ptr) { /* out of memory */ @@ -109,7 +109,7 @@ static CURL *make_handle(const char *url) curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 2000L); /* skip files larger than a gigabyte */ curl_easy_setopt(curl, CURLOPT_MAXFILESIZE_LARGE, - (curl_off_t)1024*1024*1024); + (curl_off_t)1024 * 1024 * 1024); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); curl_easy_setopt(curl, CURLOPT_FILETIME, 1L); curl_easy_setopt(curl, CURLOPT_USERAGENT, "mini crawler"); @@ -121,8 +121,7 @@ static CURL *make_handle(const char *url) } /* HREF finder implemented in libxml2 but could be any HTML parser */ -static size_t follow_links(CURLM *multi, struct memory *mem, - const char *url) +static size_t follow_links(CURLM *multi, struct memory *mem, const char *url) { int opts = HTML_PARSE_NOBLANKS | HTML_PARSE_NOERROR | \ HTML_PARSE_NOWARNING | HTML_PARSE_NONET; @@ -135,7 +134,7 @@ static size_t follow_links(CURLM *multi, struct memory *mem, xmlXPathObjectPtr result; if(!doc) return 0; - xpath = (xmlChar*) "//a/@href"; + xpath = (xmlChar *)"//a/@href"; context = xmlXPathNewContext(doc); result = xmlXPathEvalExpression(xpath, context); xmlXPathFreeContext(context); @@ -155,10 +154,10 @@ static size_t follow_links(CURLM *multi, struct memory *mem, char *link; if(follow_relative_links) { xmlChar *orig = href; - href = xmlBuildURI(href, (xmlChar *) url); + href = xmlBuildURI(href, (xmlChar *)url); xmlFree(orig); } - link = (char *) href; + link = (char *)href; if(!link || strlen(link) < 20) continue; if(!strncmp(link, "http://", 7) || !strncmp(link, "https://", 8)) { @@ -240,7 +239,7 @@ int main(void) } } else { - printf("[%d] HTTP %d: %s\n", complete, (int) res_status, url); + printf("[%d] HTTP %d: %s\n", complete, (int)res_status, url); } } else { diff --git a/docs/examples/ephiperfifo.c b/docs/examples/ephiperfifo.c index b47cbbedbf..e572fffad8 100644 --- a/docs/examples/ephiperfifo.c +++ b/docs/examples/ephiperfifo.c @@ -58,7 +58,6 @@ This is purely a demo app, all retrieved data is simply discarded by the write callback. */ - #include #include #include @@ -77,7 +76,6 @@ callback. #define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ - /* Global information, common to all connections */ struct GlobalInfo { int epfd; /* epoll filedescriptor */ @@ -105,23 +103,35 @@ struct SockInfo { struct GlobalInfo *global; }; -#define mycase(code) \ - case code: s = __STRING(code) - /* Die if we get a bad CURLMcode somewhere */ static void mcode_or_die(const char *where, CURLMcode code) { if(CURLM_OK != code) { const char *s; switch(code) { - mycase(CURLM_BAD_HANDLE); break; - mycase(CURLM_BAD_EASY_HANDLE); break; - mycase(CURLM_OUT_OF_MEMORY); break; - mycase(CURLM_INTERNAL_ERROR); break; - mycase(CURLM_UNKNOWN_OPTION); break; - mycase(CURLM_LAST); break; - default: s = "CURLM_unknown"; break; - mycase(CURLM_BAD_SOCKET); + case CURLM_BAD_HANDLE: + s = "CURLM_BAD_HANDLE"; + break; + case CURLM_BAD_EASY_HANDLE: + s = "CURLM_BAD_EASY_HANDLE"; + break; + case CURLM_OUT_OF_MEMORY: + s = "CURLM_OUT_OF_MEMORY"; + break; + case CURLM_INTERNAL_ERROR: + s = "CURLM_INTERNAL_ERROR"; + break; + case CURLM_UNKNOWN_OPTION: + s = "CURLM_UNKNOWN_OPTION"; + break; + case CURLM_LAST: + s = "CURLM_LAST"; + break; + default: + s = "CURLM_unknown"; + break; + case CURLM_BAD_SOCKET: + s = "CURLM_BAD_SOCKET"; fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); /* ignore this error */ return; @@ -161,7 +171,7 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, struct GlobalInfo *g) memset(&its, 0, sizeof(its)); } - timerfd_settime(g->tfd, /* flags= */0, &its, NULL); + timerfd_settime(g->tfd, /* flags= */ 0, &its, NULL); return 0; } @@ -281,7 +291,7 @@ static void setsock(struct SockInfo *f, curl_socket_t s, CURL *e, int act, static void addsock(curl_socket_t s, CURL *curl, int action, struct GlobalInfo *g) { - struct SockInfo *fdp = (struct SockInfo*)calloc(1, sizeof(struct SockInfo)); + struct SockInfo *fdp = (struct SockInfo *)calloc(1, sizeof(struct SockInfo)); fdp->global = g; setsock(fdp, s, curl, action, g); @@ -291,12 +301,11 @@ static void addsock(curl_socket_t s, CURL *curl, int action, /* CURLMOPT_SOCKETFUNCTION */ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { - struct GlobalInfo *g = (struct GlobalInfo*) cbp; - struct SockInfo *fdp = (struct SockInfo*) sockp; - const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; + struct GlobalInfo *g = (struct GlobalInfo *)cbp; + struct SockInfo *fdp = (struct SockInfo *)sockp; + const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; - fprintf(MSG_OUT, - "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); + fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); if(what == CURL_POLL_REMOVE) { fprintf(MSG_OUT, "\n"); remsock(fdp, g); @@ -307,8 +316,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) addsock(s, e, what, g); } else { - fprintf(MSG_OUT, - "Changing action from %s to %s\n", + fprintf(MSG_OUT, "Changing action from %s to %s\n", whatstr[fdp->action], whatstr[what]); setsock(fdp, s, e, what, g); } @@ -342,7 +350,7 @@ static void new_conn(const char *url, struct GlobalInfo *g) struct ConnInfo *conn; CURLMcode rc; - conn = (struct ConnInfo*)calloc(1, sizeof(*conn)); + conn = (struct ConnInfo *)calloc(1, sizeof(*conn)); conn->error[0] = '\0'; conn->curl = curl_easy_init(); @@ -364,8 +372,8 @@ static void new_conn(const char *url, struct GlobalInfo *g) curl_easy_setopt(conn->curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_TIME, 3L); curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_LIMIT, 10L); - fprintf(MSG_OUT, - "Adding easy %p to multi %p (%s)\n", conn->curl, g->multi, url); + fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", + conn->curl, g->multi, url); rc = curl_multi_add_handle(g->multi, conn->curl); mcode_or_die("new_conn: curl_multi_add_handle", rc); @@ -381,9 +389,9 @@ static void fifo_cb(struct GlobalInfo *g, int revents) int n = 0; do { - s[0]='\0'; + s[0] = '\0'; rv = fscanf(g->input, "%1023s%n", s, &n); - s[n]='\0'; + s[n] = '\0'; if(n && s[0]) { new_conn(s, g); /* if we read a URL, go get it! */ } @@ -437,7 +445,6 @@ static void clean_fifo(struct GlobalInfo *g) unlink(fifo); } - int g_should_exit_ = 0; void sigint_handler(int signo) @@ -506,7 +513,7 @@ int main(int argc, char **argv) while(!g_should_exit_) { int idx; int err = epoll_wait(g.epfd, events, - sizeof(events)/sizeof(struct epoll_event), 10000); + sizeof(events) / sizeof(struct epoll_event), 10000); if(err == -1) { /* !checksrc! disable ERRNOVAR 1 */ if(errno == EINTR) { diff --git a/docs/examples/evhiperfifo.c b/docs/examples/evhiperfifo.c index b6b957d54e..178be018a3 100644 --- a/docs/examples/evhiperfifo.c +++ b/docs/examples/evhiperfifo.c @@ -61,7 +61,6 @@ This is purely a demo app, all retrieved data is simply discarded by the write callback. */ - #include #include #include @@ -79,7 +78,6 @@ callback. #define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ - /* Global information, common to all connections */ struct GlobalInfo { struct ev_loop *loop; @@ -119,7 +117,7 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, struct GlobalInfo *g) ev_timer_stop(g->loop, &g->timer_event); if(timeout_ms >= 0) { /* -1 means delete, other values are timeout times in milliseconds */ - double t = timeout_ms / 1000; + double t = timeout_ms / 1000; ev_timer_init(&g->timer_event, timer_cb, t, 0.); ev_timer_start(g->loop, &g->timer_event); } @@ -196,7 +194,7 @@ static void event_cb(EV_P_ struct ev_io *w, int revents) int action; printf("%s w %p revents %i\n", __PRETTY_FUNCTION__, (void *)w, revents); - g = (struct GlobalInfo*) w->data; + g = (struct GlobalInfo *)w->data; action = ((revents & EV_READ) ? CURL_POLL_IN : 0) | ((revents & EV_WRITE) ? CURL_POLL_OUT : 0); @@ -270,15 +268,14 @@ static void addsock(curl_socket_t s, CURL *curl, int action, /* CURLMOPT_SOCKETFUNCTION */ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { - struct GlobalInfo *g = (struct GlobalInfo*) cbp; - struct SockInfo *fdp = (struct SockInfo*) sockp; - const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE"}; + struct GlobalInfo *g = (struct GlobalInfo *)cbp; + struct SockInfo *fdp = (struct SockInfo *)sockp; + const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; printf("%s e %p s %i what %i cbp %p sockp %p\n", __PRETTY_FUNCTION__, e, s, what, cbp, sockp); - fprintf(MSG_OUT, - "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); + fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); if(what == CURL_POLL_REMOVE) { fprintf(MSG_OUT, "\n"); remsock(fdp, g); @@ -289,8 +286,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) addsock(s, e, what, g); } else { - fprintf(MSG_OUT, - "Changing action from %s to %s\n", + fprintf(MSG_OUT, "Changing action from %s to %s\n", whatstr[fdp->action], whatstr[what]); setsock(fdp, s, e, what, g); } @@ -302,7 +298,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) { size_t realsize = size * nmemb; - struct ConnInfo *conn = (struct ConnInfo*) data; + struct ConnInfo *conn = (struct ConnInfo *)data; (void)ptr; (void)conn; return realsize; @@ -316,8 +312,9 @@ static int xferinfo_cb(void *p, curl_off_t dltotal, curl_off_t dlnow, (void)ult; (void)uln; - fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T - "/%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); + fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T "/" + "%" CURL_FORMAT_CURL_OFF_T ")\n", + conn->url, dlnow, dltotal); return 0; } @@ -328,7 +325,7 @@ static void new_conn(const char *url, struct GlobalInfo *g) CURLMcode rc; conn = calloc(1, sizeof(*conn)); - conn->error[0]='\0'; + conn->error[0] = '\0'; conn->curl = curl_easy_init(); if(!conn->curl) { @@ -349,8 +346,8 @@ static void new_conn(const char *url, struct GlobalInfo *g) curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_TIME, 3L); curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_LIMIT, 10L); - fprintf(MSG_OUT, - "Adding easy %p to multi %p (%s)\n", conn->curl, g->multi, url); + fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", + conn->curl, g->multi, url); rc = curl_multi_add_handle(g->multi, conn->curl); mcode_or_die("new_conn: curl_multi_add_handle", rc); @@ -369,9 +366,9 @@ static void fifo_cb(EV_P_ struct ev_io *w, int revents) (void)revents; do { - s[0]='\0'; + s[0] = '\0'; rv = fscanf(g->input, "%1023s%n", s, &n); - s[n]='\0'; + s[n] = '\0'; if(n && s[0]) { new_conn(s, g); /* if we read a URL, go get it! */ } diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c index 610a835272..632d5f2981 100644 --- a/docs/examples/externalsocket.c +++ b/docs/examples/externalsocket.c @@ -124,7 +124,7 @@ int main(void) memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; - servaddr.sin_port = htons(PORTNUM); + servaddr.sin_port = htons(PORTNUM); servaddr.sin_addr.s_addr = inet_addr(IPADDR); if(INADDR_NONE == servaddr.sin_addr.s_addr) { @@ -132,8 +132,7 @@ int main(void) return 2; } - if(connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) == - -1) { + if(connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { close(sockfd); printf("client error: connect: %s\n", strerror(errno)); return 1; diff --git a/docs/examples/ftp-wildcard.c b/docs/examples/ftp-wildcard.c index 3bd2f69083..fa66628f16 100644 --- a/docs/examples/ftp-wildcard.c +++ b/docs/examples/ftp-wildcard.c @@ -85,8 +85,7 @@ static long file_is_downloaded(void *input) return CURL_CHUNK_END_FUNC_OK; } -static size_t write_cb(char *buff, size_t size, size_t nmemb, - void *cb_data) +static size_t write_cb(char *buff, size_t size, size_t nmemb, void *cb_data) { struct callback_data *data = cb_data; size_t written = 0; @@ -104,7 +103,7 @@ int main(int argc, char **argv) CURL *curl; /* help data */ - struct callback_data data = { 0 }; + struct callback_data data = {0}; /* global initialization */ CURLcode res = curl_global_init(CURL_GLOBAL_ALL); diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index f57974de1f..4001022074 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -52,7 +52,6 @@ static size_t write_cb(void *buffer, size_t size, size_t nmemb, void *stream) return fwrite(buffer, size, nmemb, out->stream); } - int main(void) { CURL *curl; diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index eec727bf94..53ada7ccae 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -90,7 +90,7 @@ int main(void) curl_easy_cleanup(curl); } - fclose(ftpfile); /* close the local file */ + fclose(ftpfile); /* close the local file */ fclose(respfile); /* close the response file */ curl_global_cleanup(); diff --git a/docs/examples/ftpuploadfrommem.c b/docs/examples/ftpuploadfrommem.c index af88f52f1a..7c75f2b8d7 100644 --- a/docs/examples/ftpuploadfrommem.c +++ b/docs/examples/ftpuploadfrommem.c @@ -30,7 +30,7 @@ #include -static const char data[]= +static const char data[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " "___ rhoncus odio id venenatis volutpat. Vestibulum dapibus " "bibendum ullamcorper. Maecenas finibus elit augue, vel " @@ -64,7 +64,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) return copylen; } - return 0; /* no more data left to deliver */ + return 0; /* no more data left to deliver */ } int main(void) diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 1deeeda266..d4d8960487 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -37,8 +37,7 @@ struct MemoryStruct { size_t size; }; -static size_t write_cb(void *contents, size_t size, size_t nmemb, - void *userp) +static size_t write_cb(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)userp; @@ -69,8 +68,8 @@ int main(void) if(res) return (int)res; - chunk.memory = malloc(1); /* grown as needed by the realloc above */ - chunk.size = 0; /* no data at this point */ + chunk.memory = malloc(1); /* grown as needed by the realloc above */ + chunk.size = 0; /* no data at this point */ /* init the curl session */ curl = curl_easy_init(); diff --git a/docs/examples/getredirect.c b/docs/examples/getredirect.c index b1f42dc9fd..6ad9b9c1aa 100644 --- a/docs/examples/getredirect.c +++ b/docs/examples/getredirect.c @@ -54,8 +54,7 @@ int main(void) curl_easy_strerror(res)); else { res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); - if((res == CURLE_OK) && - ((response_code / 100) != 3)) { + if((res == CURLE_OK) && ((response_code / 100) != 3)) { /* a redirect implies a 3xx response code */ fprintf(stderr, "Not a redirect.\n"); } diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c index f27521971c..d7b19abb9b 100644 --- a/docs/examples/ghiper.c +++ b/docs/examples/ghiper.c @@ -171,8 +171,8 @@ static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp) { struct timeval timeout; struct GlobalInfo *g = (struct GlobalInfo *)userp; - timeout.tv_sec = timeout_ms/1000; - timeout.tv_usec = (timeout_ms%1000)*1000; + timeout.tv_sec = timeout_ms / 1000; + timeout.tv_usec = (timeout_ms % 1000) * 1000; MSG_OUT("*** update_timeout_cb %ld => %ld:%ld ***\n", timeout_ms, timeout.tv_sec, timeout.tv_usec); @@ -191,7 +191,7 @@ static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp) /* Called by glib when we get action on a multi socket */ static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) { - struct GlobalInfo *g = (struct GlobalInfo*) data; + struct GlobalInfo *g = (struct GlobalInfo *)data; CURLMcode rc; int fd = g_io_channel_unix_get_fd(ch); @@ -259,9 +259,9 @@ static void addsock(curl_socket_t s, CURL *curl, int action, /* CURLMOPT_SOCKETFUNCTION */ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { - struct GlobalInfo *g = (struct GlobalInfo*) cbp; - struct SockInfo *fdp = (struct SockInfo*) sockp; - static const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; + struct GlobalInfo *g = (struct GlobalInfo *)cbp; + struct SockInfo *fdp = (struct SockInfo *)sockp; + static const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; MSG_OUT("socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); if(what == CURL_POLL_REMOVE) { @@ -276,8 +276,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) addsock(s, e, what, g); } else { - MSG_OUT( - "Changing action from %d to %d\n", fdp->action, what); + MSG_OUT("Changing action from %d to %d\n", fdp->action, what); setsock(fdp, s, e, what, g); } } @@ -288,7 +287,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) { size_t realsize = size * nmemb; - struct ConnInfo *conn = (struct ConnInfo*) data; + struct ConnInfo *conn = (struct ConnInfo *)data; (void)ptr; (void)conn; return realsize; @@ -302,8 +301,8 @@ static int xferinfo_cb(void *p, curl_off_t dltotal, curl_off_t dlnow, (void)ult; (void)uln; - fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T - "/%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); + fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T "/" + "%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); return 0; } @@ -357,18 +356,18 @@ static gboolean fifo_cb(GIOChannel *ch, GIOCondition condition, gpointer data) rv = g_io_channel_read_line(ch, &buf, &len, &tp, &err); if(buf) { if(tp) { - buf[tp]='\0'; + buf[tp] = '\0'; } - new_conn(buf, (struct GlobalInfo*)data); + new_conn(buf, (struct GlobalInfo *)data); g_free(buf); } else { buf = g_malloc(BUF_SIZE + 1); while(TRUE) { - buf[BUF_SIZE]='\0'; + buf[BUF_SIZE] = '\0'; g_io_channel_read_chars(ch, buf, BUF_SIZE, &len, &err); if(len) { - buf[len]='\0'; + buf[len] = '\0'; if(all) { tmp = all; all = g_strdup_printf("%s%s", tmp, buf); @@ -383,7 +382,7 @@ static gboolean fifo_cb(GIOChannel *ch, GIOCondition condition, gpointer data) } } if(all) { - new_conn(all, (struct GlobalInfo*)data); + new_conn(all, (struct GlobalInfo *)data); g_free(all); } g_free(buf); diff --git a/docs/examples/headerapi.c b/docs/examples/headerapi.c index 089a23a070..e1fa33b8f6 100644 --- a/docs/examples/headerapi.c +++ b/docs/examples/headerapi.c @@ -76,7 +76,6 @@ int main(void) printf(" %s: %s (%u)\n", h->name, h->value, (unsigned int)h->amount); prev = h; } while(h); - } /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index 60288b4bd2..576bbb8d2c 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -77,7 +77,6 @@ callback. #define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ - /* Global information, common to all connections */ struct GlobalInfo { struct event_base *evbase; @@ -107,23 +106,35 @@ struct SockInfo { struct GlobalInfo *global; }; -#define mycase(code) \ - case code: s = __STRING(code) - /* Die if we get a bad CURLMcode somewhere */ static void mcode_or_die(const char *where, CURLMcode code) { if(CURLM_OK != code) { const char *s; switch(code) { - mycase(CURLM_BAD_HANDLE); break; - mycase(CURLM_BAD_EASY_HANDLE); break; - mycase(CURLM_OUT_OF_MEMORY); break; - mycase(CURLM_INTERNAL_ERROR); break; - mycase(CURLM_UNKNOWN_OPTION); break; - mycase(CURLM_LAST); break; - default: s = "CURLM_unknown"; break; - mycase(CURLM_BAD_SOCKET); + case CURLM_BAD_HANDLE: + s = "CURLM_BAD_HANDLE"; + break; + case CURLM_BAD_EASY_HANDLE: + s = "CURLM_BAD_EASY_HANDLE"; + break; + case CURLM_OUT_OF_MEMORY: + s = "CURLM_OUT_OF_MEMORY"; + break; + case CURLM_INTERNAL_ERROR: + s = "CURLM_INTERNAL_ERROR"; + break; + case CURLM_UNKNOWN_OPTION: + s = "CURLM_UNKNOWN_OPTION"; + break; + case CURLM_LAST: + s = "CURLM_LAST"; + break; + default: + s = "CURLM_unknown"; + break; + case CURLM_BAD_SOCKET: + s = "CURLM_BAD_SOCKET"; fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); /* ignore this error */ return; @@ -139,8 +150,8 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, struct GlobalInfo *g) struct timeval timeout; (void)multi; - timeout.tv_sec = timeout_ms/1000; - timeout.tv_usec = (timeout_ms%1000)*1000; + timeout.tv_sec = timeout_ms / 1000; + timeout.tv_usec = (timeout_ms % 1000) * 1000; fprintf(MSG_OUT, "multi_timer_cb: Setting timeout to %ld ms\n", timeout_ms); /* @@ -185,7 +196,7 @@ static void check_multi_info(struct GlobalInfo *g) /* Called by libevent when we get action on a multi socket */ static void event_cb(int fd, short kind, void *userp) { - struct GlobalInfo *g = (struct GlobalInfo*) userp; + struct GlobalInfo *g = (struct GlobalInfo *)userp; CURLMcode rc; int action = @@ -261,12 +272,11 @@ static void addsock(curl_socket_t s, CURL *curl, int action, /* CURLMOPT_SOCKETFUNCTION */ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { - struct GlobalInfo *g = (struct GlobalInfo*) cbp; - struct SockInfo *fdp = (struct SockInfo*) sockp; - const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; + struct GlobalInfo *g = (struct GlobalInfo *)cbp; + struct SockInfo *fdp = (struct SockInfo *)sockp; + const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; - fprintf(MSG_OUT, - "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); + fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); if(what == CURL_POLL_REMOVE) { fprintf(MSG_OUT, "\n"); remsock(fdp); @@ -277,8 +287,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) addsock(s, e, what, g); } else { - fprintf(MSG_OUT, - "Changing action from %s to %s\n", + fprintf(MSG_OUT, "Changing action from %s to %s\n", whatstr[fdp->action], whatstr[what]); setsock(fdp, s, e, what, g); } @@ -302,8 +311,8 @@ static int xferinfo_cb(void *p, curl_off_t dltotal, curl_off_t dlnow, (void)ult; (void)uln; - fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T - "/%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); + fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T "/" + "%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); return 0; } @@ -333,8 +342,8 @@ static void new_conn(const char *url, struct GlobalInfo *g) curl_easy_setopt(conn->curl, CURLOPT_XFERINFOFUNCTION, xferinfo_cb); curl_easy_setopt(conn->curl, CURLOPT_PROGRESSDATA, conn); curl_easy_setopt(conn->curl, CURLOPT_FOLLOWLOCATION, 1L); - fprintf(MSG_OUT, - "Adding easy %p to multi %p (%s)\n", conn->curl, g->multi, url); + fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", + conn->curl, g->multi, url); rc = curl_multi_add_handle(g->multi, conn->curl); mcode_or_die("new_conn: curl_multi_add_handle", rc); @@ -353,9 +362,9 @@ static void fifo_cb(int fd, short event, void *arg) (void)event; do { - s[0]='\0'; + s[0] = '\0'; rv = fscanf(g->input, "%1023s%n", s, &n); - s[n]='\0'; + s[n] = '\0'; if(n && s[0]) { if(!strcmp(s, "stop")) { g->stopped = 1; @@ -386,7 +395,7 @@ static int init_fifo(struct GlobalInfo *g) } } unlink(fifo); - if(mkfifo (fifo, 0600) == -1) { + if(mkfifo(fifo, 0600) == -1) { perror("mkfifo"); return 1; } @@ -398,7 +407,7 @@ static int init_fifo(struct GlobalInfo *g) g->input = fdopen(sockfd, "r"); fprintf(MSG_OUT, "Now, pipe some URL's into > %s\n", fifo); - event_assign(&g->fifo_event, g->evbase, sockfd, EV_READ|EV_PERSIST, + event_assign(&g->fifo_event, g->evbase, sockfd, EV_READ | EV_PERSIST, fifo_cb, g); event_add(&g->fifo_event, NULL); return 0; @@ -406,9 +415,9 @@ static int init_fifo(struct GlobalInfo *g) static void clean_fifo(struct GlobalInfo *g) { - event_del(&g->fifo_event); - fclose(g->input); - unlink(fifo); + event_del(&g->fifo_event); + fclose(g->input); + unlink(fifo); } int main(int argc, char **argv) diff --git a/docs/examples/hsts-preload.c b/docs/examples/hsts-preload.c index ad71c62cad..b029df2a0a 100644 --- a/docs/examples/hsts-preload.c +++ b/docs/examples/hsts-preload.c @@ -53,8 +53,7 @@ struct state { /* "read" is from the point of the library, it wants data from us. One domain entry per invoke. */ -static CURLSTScode hstsread(CURL *curl, struct curl_hstsentry *e, - void *userp) +static CURLSTScode hstsread(CURL *curl, struct curl_hstsentry *e, void *userp) { const char *host; const char *expire; diff --git a/docs/examples/htmltidy.c b/docs/examples/htmltidy.c index 04b4809317..9865a633ef 100644 --- a/docs/examples/htmltidy.c +++ b/docs/examples/htmltidy.c @@ -48,14 +48,14 @@ static uint write_cb(char *in, uint size, uint nmemb, TidyBuffer *out) static void dumpNode(TidyDoc doc, TidyNode tnod, int indent) { TidyNode child; - for(child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) { + for(child = tidyGetChild(tnod); child; child = tidyGetNext(child)) { ctmbstr name = tidyNodeGetName(child); if(name) { /* if it has a name, then it is an HTML tag ... */ TidyAttr attr; printf("%*.*s%s ", indent, indent, "<", name); /* walk the attribute list */ - for(attr = tidyAttrFirst(child); attr; attr = tidyAttrNext(attr) ) { + for(attr = tidyAttrFirst(child); attr; attr = tidyAttrNext(attr)) { printf("%s", tidyAttrName(attr)); tidyAttrValue(attr) ? printf("=\"%s\" ", tidyAttrValue(attr)) : printf(" "); diff --git a/docs/examples/htmltitle.cpp b/docs/examples/htmltitle.cpp index 97b924b180..a6f944ff0e 100644 --- a/docs/examples/htmltitle.cpp +++ b/docs/examples/htmltitle.cpp @@ -55,9 +55,8 @@ // libxml callback context structure // -struct Context -{ - Context(): addTitle(false) { } +struct Context { + Context() : addTitle(false) {} bool addTitle; std::string title; @@ -79,7 +78,7 @@ static size_t writer(char *data, size_t size, size_t nmemb, if(writerData == NULL) return 0; - writerData->append(data, size*nmemb); + writerData->append(data, size * nmemb); return size * nmemb; } diff --git a/docs/examples/http2-pushinmemory.c b/docs/examples/http2-pushinmemory.c index 14f37dbbbc..df896e1af5 100644 --- a/docs/examples/http2-pushinmemory.c +++ b/docs/examples/http2-pushinmemory.c @@ -115,7 +115,6 @@ static int server_push_callback(CURL *parent, return CURL_PUSH_OK; } - /* * Download a file over HTTP/2, take care of server push. */ diff --git a/docs/examples/httpput-postfields.c b/docs/examples/httpput-postfields.c index 29fd6273d7..4fd92aaffb 100644 --- a/docs/examples/httpput-postfields.c +++ b/docs/examples/httpput-postfields.c @@ -30,7 +30,7 @@ #include -static const char olivertwist[]= +static const char olivertwist[] = "Among other public buildings in a certain town, which for many reasons " "it will be prudent to refrain from mentioning, and to which I will assign " "no fictitious name, there is one anciently common to most towns, great or " diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 5c3fc314b8..026fde1210 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -77,7 +77,7 @@ int main(int argc, char **argv) { CURL *curl; CURLcode res; - FILE * hd_src; + FILE *hd_src; struct stat file_info; char *file; diff --git a/docs/examples/imap-append.c b/docs/examples/imap-append.c index 81ca682ffd..91cbac6915 100644 --- a/docs/examples/imap-append.c +++ b/docs/examples/imap-append.c @@ -64,7 +64,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) const char *data; size_t room = size * nmemb; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -95,7 +95,7 @@ int main(void) if(curl) { size_t filesize; long infilesize = LONG_MAX; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* Set username and password */ curl_easy_setopt(curl, CURLOPT_USERNAME, "user"); diff --git a/docs/examples/imap-ssl.c b/docs/examples/imap-ssl.c index 259eddc26f..52448f492d 100644 --- a/docs/examples/imap-ssl.c +++ b/docs/examples/imap-ssl.c @@ -51,7 +51,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret"); /* This fetches message 1 from the user's inbox. Note the use of - * imaps:// rather than imap:// to request an SSL based connection. */ + * imaps:// rather than imap:// to request an SSL based connection. */ curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.example.com/INBOX/;UID=1"); diff --git a/docs/examples/log_failed_transfers.c b/docs/examples/log_failed_transfers.c index a0d209ffc3..0c5c1a3b54 100644 --- a/docs/examples/log_failed_transfers.c +++ b/docs/examples/log_failed_transfers.c @@ -236,7 +236,7 @@ int main(void) curl_global_trace("all"); #endif - for(i = 0; i < sizeof(transfer)/sizeof(transfer[0]); ++i) { + for(i = 0; i < sizeof(transfer) / sizeof(transfer[0]); ++i) { int failed = 0; struct transfer *t = &transfer[i]; diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 460c93057a..d58181e027 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -66,7 +66,7 @@ int main(void) int still_running = 1; /* keep number of running handles */ - CURLMsg *msg; /* for picking up messages with the transfer status */ + CURLMsg *msg; /* for picking up messages with the transfer status */ int msgs_left; /* how many messages are left */ /* add the individual transfers */ diff --git a/docs/examples/multi-event.c b/docs/examples/multi-event.c index 2698e24678..901d7dd6e7 100644 --- a/docs/examples/multi-event.c +++ b/docs/examples/multi-event.c @@ -47,7 +47,7 @@ static struct curl_context *create_curl_context(curl_socket_t sockfd) { struct curl_context *context; - context = (struct curl_context *) malloc(sizeof(*context)); + context = (struct curl_context *)malloc(sizeof(*context)); context->sockfd = sockfd; @@ -134,10 +134,9 @@ static void curl_perform(int fd, short event, void *arg) if(event & EV_WRITE) flags |= CURL_CSELECT_OUT; - context = (struct curl_context *) arg; + context = (struct curl_context *)arg; - curl_multi_socket_action(multi, context->sockfd, flags, - &running_handles); + curl_multi_socket_action(multi, context->sockfd, flags, &running_handles); check_multi_info(); } @@ -148,8 +147,7 @@ static void on_timeout(evutil_socket_t fd, short events, void *arg) (void)fd; (void)events; (void)arg; - curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, - &running_handles); + curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, &running_handles); check_multi_info(); } @@ -186,9 +184,9 @@ static int handle_socket(CURL *curl, curl_socket_t s, int action, void *userp, case CURL_POLL_OUT: case CURL_POLL_INOUT: curl_context = socketp ? - (struct curl_context *) socketp : create_curl_context(s); + (struct curl_context *)socketp : create_curl_context(s); - curl_multi_assign(multi, s, (void *) curl_context); + curl_multi_assign(multi, s, (void *)curl_context); if(action != CURL_POLL_IN) events |= EV_WRITE; @@ -205,8 +203,8 @@ static int handle_socket(CURL *curl, curl_socket_t s, int action, void *userp, break; case CURL_POLL_REMOVE: if(socketp) { - event_del(((struct curl_context*) socketp)->event); - destroy_curl_context((struct curl_context*) socketp); + event_del(((struct curl_context *)socketp)->event); + destroy_curl_context((struct curl_context *)socketp); curl_multi_assign(multi, s, NULL); } break; diff --git a/docs/examples/multi-legacy.c b/docs/examples/multi-legacy.c index ca2c0a4c7a..e34d1cd710 100644 --- a/docs/examples/multi-legacy.c +++ b/docs/examples/multi-legacy.c @@ -72,7 +72,7 @@ int main(void) int still_running = 0; /* keep number of running handles */ - CURLMsg *msg; /* for picking up messages with the transfer status */ + CURLMsg *msg; /* for picking up messages with the transfer status */ int msgs_left; /* how many messages are left */ /* add the individual transfers */ @@ -85,7 +85,7 @@ int main(void) while(still_running) { struct timeval timeout; - int rc; /* select() return code */ + int rc; /* select() return code */ CURLMcode mc; /* curl_multi_fdset() return code */ fd_set fdread; @@ -155,7 +155,7 @@ int main(void) case -1: /* select error */ break; - case 0: /* timeout */ + case 0: /* timeout */ default: /* action */ curl_multi_perform(multi, &still_running); break; diff --git a/docs/examples/multi-uv.c b/docs/examples/multi-uv.c index 1dac320489..4053cb9061 100644 --- a/docs/examples/multi-uv.c +++ b/docs/examples/multi-uv.c @@ -60,7 +60,7 @@ static struct curl_context *create_curl_context(curl_socket_t sockfd, { struct curl_context *context; - context = (struct curl_context *) malloc(sizeof(*context)); + context = (struct curl_context *)malloc(sizeof(*context)); context->sockfd = sockfd; context->uv = uv; @@ -73,13 +73,13 @@ static struct curl_context *create_curl_context(curl_socket_t sockfd, static void curl_close_cb(uv_handle_t *handle) { - struct curl_context *context = (struct curl_context *) handle->data; + struct curl_context *context = (struct curl_context *)handle->data; free(context); } static void destroy_curl_context(struct curl_context *context) { - uv_close((uv_handle_t *) &context->poll_handle, curl_close_cb); + uv_close((uv_handle_t *)&context->poll_handle, curl_close_cb); } static void add_download(const char *url, int num, CURLM *multi) @@ -145,7 +145,7 @@ static void on_uv_socket(uv_poll_t *req, int status, int events) { int running_handles; int flags = 0; - struct curl_context *context = (struct curl_context *) req->data; + struct curl_context *context = (struct curl_context *)req->data; (void)status; if(events & UV_READABLE) flags |= CURL_CSELECT_IN; @@ -202,9 +202,9 @@ static int cb_socket(CURL *curl, curl_socket_t s, int action, case CURL_POLL_OUT: case CURL_POLL_INOUT: curl_context = socketp ? - (struct curl_context *) socketp : create_curl_context(s, uv); + (struct curl_context *)socketp : create_curl_context(s, uv); - curl_multi_assign(uv->multi, s, (void *) curl_context); + curl_multi_assign(uv->multi, s, (void *)curl_context); if(action != CURL_POLL_IN) events |= UV_WRITABLE; @@ -215,8 +215,8 @@ static int cb_socket(CURL *curl, curl_socket_t s, int action, break; case CURL_POLL_REMOVE: if(socketp) { - uv_poll_stop(&((struct curl_context*)socketp)->poll_handle); - destroy_curl_context((struct curl_context*) socketp); + uv_poll_stop(&((struct curl_context *)socketp)->poll_handle); + destroy_curl_context((struct curl_context *)socketp); curl_multi_assign(uv->multi, s, NULL); } break; @@ -230,7 +230,7 @@ static int cb_socket(CURL *curl, curl_socket_t s, int action, int main(int argc, char **argv) { CURLcode res; - struct datauv uv = { 0 }; + struct datauv uv = {0}; int running_handles; if(argc <= 1) diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c index 7de1baea90..308c1168e2 100644 --- a/docs/examples/multithread.c +++ b/docs/examples/multithread.c @@ -56,7 +56,6 @@ struct targ { const char *url; }; - static void *pull_one_url(void *p) { CURL *curl; @@ -72,7 +71,6 @@ static void *pull_one_url(void *p) return NULL; } - /* int pthread_create(pthread_t *new_thread_ID, const pthread_attr_t *attr, diff --git a/docs/examples/netrc.c b/docs/examples/netrc.c index 91f8df96dc..a9eaebff88 100644 --- a/docs/examples/netrc.c +++ b/docs/examples/netrc.c @@ -40,8 +40,7 @@ int main(void) curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); - curl_easy_setopt(curl, CURLOPT_NETRC_FILE, - "/home/daniel/s3cr3ts.txt"); + curl_easy_setopt(curl, CURLOPT_NETRC_FILE, "/home/daniel/s3cr3ts.txt"); curl_easy_setopt(curl, CURLOPT_URL, "https://curl.se/"); res = curl_easy_perform(curl); diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index bbab002790..c463e3785c 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -47,7 +47,7 @@ struct WriteThis { static size_t read_cb(char *dest, size_t size, size_t nmemb, void *userp) { struct WriteThis *wt = (struct WriteThis *)userp; - size_t buffer_size = size*nmemb; + size_t buffer_size = size * nmemb; if(wt->sizeleft) { /* copy as much as possible from the source to the destination */ diff --git a/docs/examples/postinmemory.c b/docs/examples/postinmemory.c index fc42251ddd..089d9a9c74 100644 --- a/docs/examples/postinmemory.c +++ b/docs/examples/postinmemory.c @@ -36,8 +36,7 @@ struct MemoryStruct { size_t size; }; -static size_t write_cb(void *contents, size_t size, size_t nmemb, - void *userp) +static size_t write_cb(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)userp; @@ -104,7 +103,7 @@ int main(void) * * Do something nice with it! */ - printf("%s\n",chunk.memory); + printf("%s\n", chunk.memory); } /* always cleanup */ diff --git a/docs/examples/sftpget.c b/docs/examples/sftpget.c index 287d5b253e..470474cafd 100644 --- a/docs/examples/sftpget.c +++ b/docs/examples/sftpget.c @@ -50,8 +50,7 @@ struct FtpFile { FILE *stream; }; -static size_t write_cb(void *buffer, size_t size, size_t nmemb, - void *stream) +static size_t write_cb(void *buffer, size_t size, size_t nmemb, void *stream) { struct FtpFile *out = (struct FtpFile *)stream; if(!out->stream) { @@ -63,7 +62,6 @@ static size_t write_cb(void *buffer, size_t size, size_t nmemb, return fwrite(buffer, size, nmemb, out->stream); } - int main(void) { CURL *curl; diff --git a/docs/examples/sftpuploadresume.c b/docs/examples/sftpuploadresume.c index 84bb425549..9b78f96ee4 100644 --- a/docs/examples/sftpuploadresume.c +++ b/docs/examples/sftpuploadresume.c @@ -83,7 +83,6 @@ static curl_off_t sftpGetRemoteFileSize(const char *i_remoteFile) return remoteFileSizeByte; } - static int sftpResumeUpload(CURL *curl, const char *remotepath, const char *localpath) { diff --git a/docs/examples/shared-connection-cache.c b/docs/examples/shared-connection-cache.c index bc1239428b..acaa610dec 100644 --- a/docs/examples/shared-connection-cache.c +++ b/docs/examples/shared-connection-cache.c @@ -29,8 +29,8 @@ #include -static void my_lock(CURL *curl, curl_lock_data data, - curl_lock_access laccess, void *useptr) +static void my_lock(CURL *curl, curl_lock_data data, curl_lock_access laccess, + void *useptr) { (void)curl; (void)data; diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index a41a9ac29e..3cf4b462bd 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -68,11 +68,11 @@ int main(void) const char *pKeyType; #ifdef USE_ENGINE - pKeyName = "rsa_test"; - pKeyType = "ENG"; + pKeyName = "rsa_test"; + pKeyType = "ENG"; #else - pKeyName = "testkey.pem"; - pKeyType = "PEM"; + pKeyName = "testkey.pem"; + pKeyType = "PEM"; #endif res = curl_global_init(CURL_GLOBAL_ALL); diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c index 2a3cdbc0ef..6bf8946721 100644 --- a/docs/examples/smooth-gtk-thread.c +++ b/docs/examples/smooth-gtk-thread.c @@ -108,11 +108,10 @@ static void *pull_one_url(void *NaN) return NULL; } - static gboolean pulse_bar(gpointer data) { gdk_threads_enter(); - gtk_progress_bar_pulse(GTK_PROGRESS_BAR (data)); + gtk_progress_bar_pulse(GTK_PROGRESS_BAR(data)); gdk_threads_leave(); /* Return true so the function is called again; returning false removes this @@ -127,7 +126,7 @@ static void *create_thread(void *progress_bar) int i; /* Make sure I do not create more threads than urls. */ - for(i = 0; i < NUMT && i < num_urls ; i++) { + for(i = 0; i < NUMT && i < num_urls; i++) { int error = pthread_create(&tid[i], NULL, /* default attributes please */ pull_one_url, @@ -196,7 +195,7 @@ int main(int argc, char **argv) /* Progress bar */ progress_bar = gtk_progress_bar_new(); - gtk_progress_bar_pulse(GTK_PROGRESS_BAR (progress_bar)); + gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar)); /* Make uniform pulsing */ gint pulse_ref = g_timeout_add(300, pulse_bar, progress_bar); g_object_set_data(G_OBJECT(progress_bar), "pulse_id", @@ -206,7 +205,7 @@ int main(int argc, char **argv) gtk_widget_show_all(top_window); printf("gtk_widget_show_all\n"); - g_signal_connect(G_OBJECT (top_window), "delete-event", + g_signal_connect(G_OBJECT(top_window), "delete-event", G_CALLBACK(cb_delete), NULL); if(!g_thread_create(&create_thread, progress_bar, FALSE, NULL) != 0) diff --git a/docs/examples/smtp-authzid.c b/docs/examples/smtp-authzid.c index a375d839b1..e7dd20f590 100644 --- a/docs/examples/smtp-authzid.c +++ b/docs/examples/smtp-authzid.c @@ -73,7 +73,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) size_t room = size * nmemb; size_t len; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -99,7 +99,7 @@ int main(void) curl = curl_easy_init(); if(curl) { struct curl_slist *recipients = NULL; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* This is the URL for your mailserver. In this example we connect to the smtp-submission port as we require an authenticated connection. */ diff --git a/docs/examples/smtp-mail.c b/docs/examples/smtp-mail.c index e6e77b97a3..d5074abbf2 100644 --- a/docs/examples/smtp-mail.c +++ b/docs/examples/smtp-mail.c @@ -70,7 +70,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) size_t room = size * nmemb; size_t len; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -96,7 +96,7 @@ int main(void) curl = curl_easy_init(); if(curl) { struct curl_slist *recipients = NULL; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* This is the URL for your mailserver */ curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); diff --git a/docs/examples/smtp-multi.c b/docs/examples/smtp-multi.c index ab7165cd52..8cb5e65a26 100644 --- a/docs/examples/smtp-multi.c +++ b/docs/examples/smtp-multi.c @@ -63,7 +63,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) size_t room = size * nmemb; size_t len; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -94,7 +94,7 @@ int main(void) if(multi) { int still_running = 1; struct curl_slist *recipients = NULL; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* This is the URL for your mailserver */ curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); diff --git a/docs/examples/smtp-ssl.c b/docs/examples/smtp-ssl.c index 4ebc58f1b5..3b140c904c 100644 --- a/docs/examples/smtp-ssl.c +++ b/docs/examples/smtp-ssl.c @@ -67,7 +67,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) size_t room = size * nmemb; size_t len; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -93,7 +93,7 @@ int main(void) curl = curl_easy_init(); if(curl) { struct curl_slist *recipients = NULL; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* Set username and password */ curl_easy_setopt(curl, CURLOPT_USERNAME, "user"); diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c index f6b3bb6053..3bf3b0cddf 100644 --- a/docs/examples/smtp-tls.c +++ b/docs/examples/smtp-tls.c @@ -67,7 +67,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) size_t room = size * nmemb; size_t len; - if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { return 0; } @@ -93,7 +93,7 @@ int main(void) curl = curl_easy_init(); if(curl) { struct curl_slist *recipients = NULL; - struct upload_status upload_ctx = { 0 }; + struct upload_status upload_ctx = {0}; /* Set username and password */ curl_easy_setopt(curl, CURLOPT_USERNAME, "user"); diff --git a/docs/examples/sslbackend.c b/docs/examples/sslbackend.c index fd2b57534e..5615bec72d 100644 --- a/docs/examples/sslbackend.c +++ b/docs/examples/sslbackend.c @@ -38,7 +38,7 @@ * SSL backend has to be configured). * * **** This example only works with libcurl 7.56.0 and later! **** -*/ + */ int main(int argc, char **argv) { diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index a9a746c30a..b2a3b92607 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -66,7 +66,11 @@ #include #ifndef _WIN32 -int main(void) { printf("Platform not supported.\n"); return 1; } +int main(void) +{ + printf("Platform not supported.\n"); + return 1; +} #else #if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ @@ -79,7 +83,11 @@ int main(void) { printf("Platform not supported.\n"); return 1; } #endif #ifdef CURL_WINDOWS_UWP -int main(void) { printf("Platform not supported.\n"); return 1; } +int main(void) +{ + printf("Platform not supported.\n"); + return 1; +} #else #include @@ -123,8 +131,7 @@ static SYSTEMTIME LOCALTime; #define HTTP_COMMAND_HEAD 0 #define HTTP_COMMAND_GET 1 -static size_t write_cb(void *ptr, size_t size, size_t nmemb, - void *stream) +static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream) { fwrite(ptr, size, nmemb, stream); return nmemb * size; @@ -280,7 +287,7 @@ int main(int argc, char *argv[]) snprintf(conf->http_proxy, MAX_STRING, "%s", &argv[OptionIndex][8]); if((strcmp(argv[OptionIndex], "--help") == 0) || - (strcmp(argv[OptionIndex], "/?") == 0)) { + (strcmp(argv[OptionIndex], "/?") == 0)) { showUsage(); return 0; } @@ -317,9 +324,9 @@ int main(int argc, char *argv[]) gmt = gmtime(&tt); tt_gmt = mktime(gmt); tzonediffFloat = difftime(tt_local, tt_gmt); - tzonediffWord = (int)(tzonediffFloat/3600.0); + tzonediffWord = (int)(tzonediffFloat / 3600.0); - if(tzonediffWord == (int)(tzonediffFloat/3600.0)) + if(tzonediffWord == (int)(tzonediffFloat / 3600.0)) snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'00'", tzonediffWord); else snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'30'", tzonediffWord); @@ -329,9 +336,8 @@ int main(int argc, char *argv[]) GetLocalTime(&LOCALTime); snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, - MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, - LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, - LOCALTime.wMilliseconds); + MthStr[LOCALTime.wMonth - 1], LOCALTime.wYear, LOCALTime.wHour, + LOCALTime.wMinute, LOCALTime.wSecond, LOCALTime.wMilliseconds); fprintf(stderr, "Fetch: %s\n\n", conf->timeserver); fprintf(stderr, "Before HTTP. Date: %s%s\n\n", timeBuf, tzoneBuf); @@ -343,9 +349,8 @@ int main(int argc, char *argv[]) GetLocalTime(&LOCALTime); snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, - MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, - LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, - LOCALTime.wMilliseconds); + MthStr[LOCALTime.wMonth - 1], LOCALTime.wYear, LOCALTime.wHour, + LOCALTime.wMinute, LOCALTime.wSecond, LOCALTime.wMilliseconds); fprintf(stderr, "\nAfter HTTP. Date: %s%s\n", timeBuf, tzoneBuf); if(AutoSyncTime == 3) { @@ -359,7 +364,7 @@ int main(int argc, char *argv[]) GetLocalTime(&LOCALTime); snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, - MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, + MthStr[LOCALTime.wMonth - 1], LOCALTime.wYear, LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, LOCALTime.wMilliseconds); fprintf(stderr, "\nNew System's Date: %s%s\n", timeBuf, tzoneBuf); diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c index 8119113695..8d5d1234fc 100644 --- a/docs/examples/threaded-ssl.c +++ b/docs/examples/threaded-ssl.c @@ -46,7 +46,7 @@ #define NUMT 4 /* List of URLs to fetch.*/ -static const char * const urls[]= { +static const char * const urls[] = { "https://www.example.com/", "https://www2.example.com/", "https://www3.example.com/", diff --git a/docs/examples/usercertinmem.c b/docs/examples/usercertinmem.c index 175dae1151..44a0a15bc7 100644 --- a/docs/examples/usercertinmem.c +++ b/docs/examples/usercertinmem.c @@ -114,7 +114,7 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer) } /* tell SSL to use the X509 certificate */ - ret = SSL_CTX_use_certificate((SSL_CTX*)sslctx, cert); + ret = SSL_CTX_use_certificate((SSL_CTX *)sslctx, cert); if(ret != 1) { printf("Use certificate failed\n"); } @@ -132,7 +132,7 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer) } /* tell SSL to use the RSA key from memory */ - ret = SSL_CTX_use_RSAPrivateKey((SSL_CTX*)sslctx, rsa); + ret = SSL_CTX_use_RSAPrivateKey((SSL_CTX *)sslctx, rsa); if(ret != 1) { printf("Use Key failed\n"); } diff --git a/docs/examples/xmlstream.c b/docs/examples/xmlstream.c index 0aec24cc67..5b35d04861 100644 --- a/docs/examples/xmlstream.c +++ b/docs/examples/xmlstream.c @@ -55,7 +55,7 @@ struct ParserStruct { static void startElement(void *userData, const XML_Char *name, const XML_Char **atts) { - struct ParserStruct *state = (struct ParserStruct *) userData; + struct ParserStruct *state = (struct ParserStruct *)userData; state->tags++; state->depth++; @@ -70,7 +70,7 @@ static void startElement(void *userData, const XML_Char *name, static void characterDataHandler(void *userData, const XML_Char *s, int len) { - struct ParserStruct *state = (struct ParserStruct *) userData; + struct ParserStruct *state = (struct ParserStruct *)userData; struct MemoryStruct *mem = &state->characters; char *ptr = realloc(mem->memory, mem->size + (unsigned long)len + 1); @@ -89,7 +89,7 @@ static void characterDataHandler(void *userData, const XML_Char *s, int len) static void endElement(void *userData, const XML_Char *name) { - struct ParserStruct *state = (struct ParserStruct *) userData; + struct ParserStruct *state = (struct ParserStruct *)userData; state->depth--; printf("%5lu %10lu %s\n", state->depth, state->characters.size, name); @@ -98,9 +98,9 @@ static void endElement(void *userData, const XML_Char *name) static size_t write_cb(void *contents, size_t length, size_t nmemb, void *userp) { - XML_Parser parser = (XML_Parser) userp; + XML_Parser parser = (XML_Parser)userp; size_t real_size = length * nmemb; - struct ParserStruct *state = (struct ParserStruct *) XML_GetUserData(parser); + struct ParserStruct *state = (struct ParserStruct *)XML_GetUserData(parser); /* Only parse if we are not already in a failure state. */ if(state->ok && XML_Parse(parser, contents, (int)real_size, 0) == 0) {