diff options
author | Marcel Raad <Marcel.Raad@teamviewer.com> | 2019-05-21 10:44:16 +0200 |
---|---|---|
committer | Marcel Raad <Marcel.Raad@teamviewer.com> | 2019-05-22 10:06:21 +0200 |
commit | 10b7067eb722bf2bc19f4dd6d97199be705baea2 (patch) | |
tree | d6a5e6ff76b923997ab6f859ac3d1015e9c30f81 /docs | |
parent | 918987a844912b431f132b5c4d49fb73a0cb1a0e (diff) | |
download | curl-10b7067eb722bf2bc19f4dd6d97199be705baea2.tar.gz |
examples: reduce variable scopes
Closes https://github.com/curl/curl/pull/3919
Diffstat (limited to 'docs')
-rw-r--r-- | docs/examples/cacertinmem.c | 3 | ||||
-rw-r--r-- | docs/examples/curlgtk.c | 5 | ||||
-rw-r--r-- | docs/examples/ephiperfifo.c | 7 | ||||
-rw-r--r-- | docs/examples/htmltidy.c | 13 | ||||
-rw-r--r-- | docs/examples/imap-append.c | 11 | ||||
-rw-r--r-- | docs/examples/multi-app.c | 4 | ||||
-rw-r--r-- | docs/examples/sendrecv.c | 7 | ||||
-rw-r--r-- | docs/examples/shared-connection-cache.c | 6 | ||||
-rw-r--r-- | docs/examples/smooth-gtk-thread.c | 9 | ||||
-rw-r--r-- | docs/examples/smtp-mime.c | 15 | ||||
-rw-r--r-- | docs/examples/synctime.c | 22 |
11 files changed, 51 insertions, 51 deletions
diff --git a/docs/examples/cacertinmem.c b/docs/examples/cacertinmem.c index 071031707..11cc06bee 100644 --- a/docs/examples/cacertinmem.c +++ b/docs/examples/cacertinmem.c @@ -85,7 +85,6 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm) BIO *cbio = BIO_new_mem_buf(mypem, sizeof(mypem)); X509_STORE *cts = SSL_CTX_get_cert_store((SSL_CTX *)sslctx); - X509_INFO *itmp; int i; STACK_OF(X509_INFO) *inf; (void)curl; @@ -103,7 +102,7 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm) } for(i = 0; i < sk_X509_INFO_num(inf); i++) { - itmp = sk_X509_INFO_value(inf, i); + X509_INFO *itmp = sk_X509_INFO_value(inf, i); if(itmp->x509) { X509_STORE_add_cert(cts, itmp->x509); } diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index 35b60da63..4083c8f95 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -45,13 +45,12 @@ int my_progress_func(GtkWidget *bar, void *my_thread(void *ptr) { CURL *curl; - FILE *outfile; - gchar *url = ptr; curl = curl_easy_init(); if(curl) { + gchar *url = ptr; const char *filename = "test.curl"; - outfile = fopen(filename, "wb"); + FILE *outfile = fopen(filename, "wb"); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); diff --git a/docs/examples/ephiperfifo.c b/docs/examples/ephiperfifo.c index a4b90fe4f..2b8f4cc6e 100644 --- a/docs/examples/ephiperfifo.c +++ b/docs/examples/ephiperfifo.c @@ -472,8 +472,6 @@ void SignalHandler(int signo) int main(int argc _Unused, char **argv _Unused) { GlobalInfo g; - int err; - int idx; struct itimerspec its; struct epoll_event ev; struct epoll_event events[10]; @@ -518,8 +516,9 @@ int main(int argc _Unused, char **argv _Unused) fprintf(MSG_OUT, "Entering wait loop\n"); fflush(MSG_OUT); while(!g_should_exit_) { - err = epoll_wait(g.epfd, events, sizeof(events)/sizeof(struct epoll_event), - 10000); + int idx; + int err = epoll_wait(g.epfd, events, + sizeof(events)/sizeof(struct epoll_event), 10000); if(err == -1) { if(errno == EINTR) { fprintf(MSG_OUT, "note: wait interrupted\n"); diff --git a/docs/examples/htmltidy.c b/docs/examples/htmltidy.c index 2f4500f51..1b48e0a2e 100644 --- a/docs/examples/htmltidy.c +++ b/docs/examples/htmltidy.c @@ -74,13 +74,14 @@ void dumpNode(TidyDoc doc, TidyNode tnod, int indent) int main(int argc, char **argv) { - CURL *curl; - char curl_errbuf[CURL_ERROR_SIZE]; - TidyDoc tdoc; - TidyBuffer docbuf = {0}; - TidyBuffer tidy_errbuf = {0}; - int err; if(argc == 2) { + CURL *curl; + char curl_errbuf[CURL_ERROR_SIZE]; + TidyDoc tdoc; + TidyBuffer docbuf = {0}; + TidyBuffer tidy_errbuf = {0}; + int err; + curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, argv[1]); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf); diff --git a/docs/examples/imap-append.c b/docs/examples/imap-append.c index bbf9fe436..157d5749a 100644 --- a/docs/examples/imap-append.c +++ b/docs/examples/imap-append.c @@ -85,14 +85,15 @@ int main(void) { CURL *curl; CURLcode res = CURLE_OK; - const char **p; - long infilesize; - struct upload_status upload_ctx; - - upload_ctx.lines_read = 0; curl = curl_easy_init(); if(curl) { + const char **p; + long infilesize; + struct upload_status upload_ctx; + + upload_ctx.lines_read = 0; + /* Set username and password */ curl_easy_setopt(curl, CURLOPT_USERNAME, "user"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret"); diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 78867d835..b98a25161 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -147,11 +147,11 @@ int main(void) /* See how the transfers went */ while((msg = curl_multi_info_read(multi_handle, &msgs_left))) { if(msg->msg == CURLMSG_DONE) { - int idx, found = 0; + int idx; /* Find out which handle this message is about */ for(idx = 0; idx<HANDLECOUNT; idx++) { - found = (msg->easy_handle == handles[idx]); + int found = (msg->easy_handle == handles[idx]); if(found) break; } diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index cf764be43..5660a7955 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -59,12 +59,9 @@ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms) int main(void) { CURL *curl; - CURLcode res; /* Minimalistic http request */ const char *request = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n"; size_t request_len = strlen(request); - curl_socket_t sockfd; - size_t nsent_total = 0; /* A general note of caution here: if you're using curl_easy_recv() or curl_easy_send() to implement HTTP or _any_ other protocol libcurl @@ -76,6 +73,10 @@ int main(void) curl = curl_easy_init(); if(curl) { + CURLcode res; + curl_socket_t sockfd; + size_t nsent_total = 0; + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); /* Do not do the transfer - only connect to host */ curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); diff --git a/docs/examples/shared-connection-cache.c b/docs/examples/shared-connection-cache.c index 91864d9b2..639ad9c54 100644 --- a/docs/examples/shared-connection-cache.c +++ b/docs/examples/shared-connection-cache.c @@ -46,8 +46,6 @@ static void my_unlock(CURL *handle, curl_lock_data data, void *useptr) int main(void) { - CURL *curl; - CURLcode res; CURLSH *share; int i; @@ -61,8 +59,10 @@ int main(void) still reuse connections since the pool is in the shared object! */ for(i = 0; i < 3; i++) { - curl = curl_easy_init(); + CURL *curl = curl_easy_init(); if(curl) { + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, "https://curl.haxx.se/"); /* use the share object */ diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c index 66d8c10b5..b64c48610 100644 --- a/docs/examples/smooth-gtk-thread.c +++ b/docs/examples/smooth-gtk-thread.c @@ -67,13 +67,12 @@ size_t write_file(void *ptr, size_t size, size_t nmemb, FILE *stream) /* https://weather.com/weather/today/l/46214?cc=*&dayf=5&unit=i */ void *pull_one_url(void *NaN) { - CURL *curl; - gchar *http; - FILE *outfile; - /* Stop threads from entering unless j is incremented */ pthread_mutex_lock(&lock); while(j < num_urls) { + CURL *curl; + gchar *http; + printf("j = %d\n", j); http = @@ -85,7 +84,7 @@ void *pull_one_url(void *NaN) curl = curl_easy_init(); if(curl) { - outfile = fopen(urls[j], "wb"); + FILE *outfile = fopen(urls[j], "wb"); /* Set the URL and transfer type */ curl_easy_setopt(curl, CURLOPT_URL, http); diff --git a/docs/examples/smtp-mime.c b/docs/examples/smtp-mime.c index 35997fa0e..4f3fbfd53 100644 --- a/docs/examples/smtp-mime.c +++ b/docs/examples/smtp-mime.c @@ -70,16 +70,17 @@ int main(void) { CURL *curl; CURLcode res = CURLE_OK; - struct curl_slist *headers = NULL; - struct curl_slist *recipients = NULL; - struct curl_slist *slist = NULL; - curl_mime *mime; - curl_mime *alt; - curl_mimepart *part; - const char **cpp; curl = curl_easy_init(); if(curl) { + struct curl_slist *headers = NULL; + struct curl_slist *recipients = NULL; + struct curl_slist *slist = NULL; + curl_mime *mime; + curl_mime *alt; + curl_mimepart *part; + const char **cpp; + /* This is the URL for your mailserver */ curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index d84cea913..905f51189 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -257,25 +257,15 @@ int main(int argc, char *argv[]) { CURL *curl; conf_t conf[1]; - int OptionIndex; - struct tm *lt; - struct tm *gmt; - time_t tt; - time_t tt_local; - time_t tt_gmt; - double tzonediffFloat; - int tzonediffWord; - char timeBuf[61]; - char tzoneBuf[16]; int RetValue; - OptionIndex = 0; ShowAllHeader = 0; /* Do not show HTTP Header */ AutoSyncTime = 0; /* Do not synchronise computer clock */ RetValue = 0; /* Successful Exit */ conf_init(conf); if(argc > 1) { + int OptionIndex = 0; while(OptionIndex < argc) { if(strncmp(argv[OptionIndex], "--server=", 9) == 0) snprintf(conf->timeserver, MAX_STRING, "%s", &argv[OptionIndex][9]); @@ -308,6 +298,16 @@ int main(int argc, char *argv[]) curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { + struct tm *lt; + struct tm *gmt; + time_t tt; + time_t tt_local; + time_t tt_gmt; + double tzonediffFloat; + int tzonediffWord; + char timeBuf[61]; + char tzoneBuf[16]; + SyncTime_CURL_Init(curl, conf->http_proxy, conf->proxy_user); /* Calculating time diff between GMT and localtime */ |