docs/libcurl: fix C formatting nits

Closes #19844
This commit is contained in:
Viktor Szakats 2025-12-04 20:11:45 +01:00
parent 6d042273cd
commit ebe6fa08c9
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
13 changed files with 28 additions and 31 deletions

View File

@ -83,7 +83,7 @@ int main(void)
}
/* extract the normal headers + 1xx + trailers from the last request */
unsigned int origin = CURLH_HEADER| CURLH_1XX | CURLH_TRAILER;
unsigned int origin = CURLH_HEADER | CURLH_1XX | CURLH_TRAILER;
while((h = curl_easy_nextheader(curl, origin, -1, prev))) {
printf("%s: %s\n", h->name, h->value);
prev = h;

View File

@ -109,7 +109,6 @@ int main(void)
if(curl) {
/* pause a transfer in both directions */
curl_easy_pause(curl, CURLPAUSE_RECV | CURLPAUSE_SEND);
}
}
~~~

View File

@ -225,7 +225,7 @@ int main(void)
char file2[] = "your-face.jpg";
/* add null character into htmlbuffer, to demonstrate that
transfers of buffers containing null characters actually work
*/
*/
htmlbuffer[8] = '\0';
/* Add simple name/content section */

View File

@ -54,7 +54,7 @@ This, because first then does libcurl known which actual read callback to use.
size_t print_httppost_callback(void *arg, const char *buf, size_t len)
{
fwrite(buf, len, 1, stdout);
(*(size_t *) arg) += len;
(*(size_t *)arg) += len;
return len;
}
@ -62,7 +62,7 @@ size_t print_httppost(struct curl_httppost *post)
{
size_t total_size = 0;
if(curl_formget(post, &total_size, print_httppost_callback)) {
return (size_t) -1;
return (size_t)-1;
}
return total_size;
}

View File

@ -120,7 +120,7 @@ struct ctl {
size_t read_callback(char *buffer, size_t size, size_t nitems, void *arg)
{
struct ctl *p = (struct ctl *) arg;
struct ctl *p = (struct ctl *)arg;
curl_off_t sz = p->size - p->position;
nitems *= size;

View File

@ -274,7 +274,7 @@ const char *name = "John";
int main(void)
{
curl_mprintf("My name is %s\n", name);
curl_mprintf("Pi is almost %f\n", (double)25.0/8);
curl_mprintf("Pi is almost %f\n", (double)25.0 / 8);
}
~~~

View File

@ -92,7 +92,7 @@ int main(void)
int maxfd;
int rc;
CURLMcode mc;
struct timeval timeout = {1, 0};
struct timeval timeout = { 1, 0 };
CURLM *multi = curl_multi_init();

View File

@ -137,8 +137,7 @@ struct customdata {
void *ptr;
};
static size_t writecb(char *buffer,
size_t size, size_t nitems, void *p)
static size_t writecb(char *buffer, size_t size, size_t nitems, void *p)
{
struct customdata *c = (struct customdata *)p;
const struct curl_ws_frame *m = curl_ws_meta(c->easy);
@ -158,7 +157,6 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &custom);
curl_easy_perform(curl);
}
return 0;
}

View File

@ -448,7 +448,7 @@ claims to support. This method does however add a round-trip since libcurl
must first ask the server what it supports:
~~~c
curl_easy_setopt(handle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST|CURLAUTH_BASIC);
curl_easy_setopt(handle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST | CURLAUTH_BASIC);
~~~
For convenience, you can use the *CURLAUTH_ANY* define (instead of a list with
@ -468,7 +468,7 @@ pages using the \<form\> tag uses. We provide a pointer to the data and tell
libcurl to post it all to the remote site:
~~~c
char *data="name=daniel&project=curl";
char *data = "name=daniel&project=curl";
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(handle, CURLOPT_URL, "http://posthere.com/");
@ -487,7 +487,7 @@ done in a generic way, by building a list of our own headers and then passing
that list to libcurl.
~~~c
struct curl_slist *headers=NULL;
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: text/xml");
/* post binary data */
@ -574,8 +574,8 @@ parts, you post the whole form.
The MIME API example above is expressed as follows using this function:
~~~c
struct curl_httppost *post=NULL;
struct curl_httppost *last=NULL;
struct curl_httppost *post = NULL;
struct curl_httppost *last = NULL;
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "name",
CURLFORM_COPYCONTENTS, "daniel", CURLFORM_END);
@ -605,7 +605,7 @@ shows how you set headers to one specific part when you add that to the post
handle:
~~~c
struct curl_slist *headers=NULL;
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: text/xml");
curl_formadd(&post, &last,
@ -675,7 +675,7 @@ becomes:
~~~c
part = curl_mime_addpart(multipart);
curl_mime_name(part, "logotype-image");
curl_mime_data_cb(part, (curl_off_t) -1, fread, fseek, NULL, stdin);
curl_mime_data_cb(part, (curl_off_t)-1, fread, fseek, NULL, stdin);
~~~
curl_mime_name(3) always copies the field name. The special filename "-" is
@ -717,7 +717,7 @@ becomes:
~~~c
part = curl_mime_addpart(multipart);
curl_mime_name(part, "stream");
curl_mime_data_cb(part, (curl_off_t) datasize,
curl_mime_data_cb(part, (curl_off_t)datasize,
myreadfunc, NULL, NULL, arg);
curl_mime_filename(part, "archive.zip");
curl_mime_type(part, "application/zip");
@ -738,7 +738,7 @@ becomes:
~~~c
part = curl_mime_addpart(multipart);
curl_mime_name(part, "memfile");
curl_mime_data(part, databuffer, (curl_off_t) sizeof databuffer);
curl_mime_data(part, databuffer, (curl_off_t)sizeof(databuffer));
curl_mime_filename(part, "memfile.bin");
~~~
@ -802,12 +802,12 @@ Example C++ code:
~~~c
class AClass {
static size_t write_data(void *ptr, size_t size, size_t nmemb,
void *ourpointer)
{
/* do what you want with the data */
}
}
static size_t write_data(void *ptr, size_t size, size_t nmemb,
void *ourpointer)
{
/* do what you want with the data */
}
}
~~~
# Proxies
@ -1046,7 +1046,7 @@ request, and you are free to pass any amount of extra headers that you
think fit. Adding headers is this easy:
~~~c
struct curl_slist *headers=NULL; /* init to NULL is important */
struct curl_slist *headers = NULL; /* init to NULL is important */
headers = curl_slist_append(headers, "Hey-server-hey: how are you?");
headers = curl_slist_append(headers, "X-silly-content: yes");

View File

@ -53,7 +53,7 @@ int main(int argc, char *argv[])
long used;
res = curl_easy_getinfo(curl, CURLINFO_USED_PROXY, &used);
if(!res) {
printf("The proxy was %sused\n", used ? "": "NOT ");
printf("The proxy was %sused\n", used ? "" : "NOT ");
}
}
curl_easy_cleanup(curl);

View File

@ -77,7 +77,7 @@ NULL
~~~c
/* an inline import of a cookie in Netscape format. */
#define SEP "\t" /* Tab separates the fields */
#define SEP "\t" /* Tab separates the fields */
int main(void)
{

View File

@ -35,7 +35,7 @@ password with the CURLOPT_PROXYUSERPWD(3) option.
# DEFAULT
CURLAUTH_BASIC|CURLAUTH_GSSAPI
CURLAUTH_BASIC | CURLAUTH_GSSAPI
# %PROTOCOLS%

View File

@ -106,7 +106,7 @@ static size_t cb(char *data, size_t size, size_t nmemb, void *clientp)
int main(void)
{
struct memory chunk = {0};
struct memory chunk = { 0 };
CURLcode res;
CURL *curl = curl_easy_init();
if(curl) {