1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

examples: reduce variable scopes

Closes https://github.com/curl/curl/pull/3919
This commit is contained in:
Marcel Raad 2019-05-21 10:44:16 +02:00
parent 918987a844
commit 10b7067eb7
No known key found for this signature in database
GPG Key ID: 33C416EFAE4D6F02
11 changed files with 51 additions and 51 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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");

View File

@ -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);

View File

@ -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");

View File

@ -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;
}

View File

@ -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);

View File

@ -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 */

View File

@ -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);

View File

@ -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");

View File

@ -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 */