curl/docs/examples
Viktor Szakats 08c7c937dc
tidy-up: prefer return over exit(), fix fallouts
To avoid breaking the control flow and align to majority of code
already using `return`.

`exit()` has the side-effect of suppressing leak detection in cases.
Fix fallouts detected after switching to `return`.

- configure:
  - fix `getaddrinfo` run test to call `freeaddrinfo()` to pacify ASAN,
    and call `WSACleanup()` to deinit winsock2.
  - fix `getifaddrs` run test to call `freeifaddrs()` to pacify ASAN.
- tests/server:
  - setup `atexit(win32_cleanup)` via `win32_init()`.
  - return 2 instead of 1 on winsock2 init failures.
  - sws: goto cleanup instead of `exit()` in `http_connect()`.
    Follow-up to 02dfe71937 #7235
- tests/client/http:
  - cleanup memory to pacify ASAN in `h2-upgrade-extreme`,
    `tls-session-reuse`.
- examples:
  - block_ip: fix memory leak reported by CI.
  - http2-upload: avoid handle leaks.

Untouched `exit()` calls, made from callbacks:
- docs/examples: ephiperfifo.c, ghiper.c, hiperfifo.c
- tests/libtest: lib582.c, lib655.c, lib670.c
- tests/server: tftpd.c

Closes #16507
2025-02-28 13:11:41 +01:00
..
.checksrc
.gitignore
10-at-a-time.c
adddocsref.pl
address-scope.c
altsvc.c
anyauthput.c
block_ip.c tidy-up: prefer return over exit(), fix fallouts 2025-02-28 13:11:41 +01:00
cacertinmem.c
certinfo.c
chkspeed.c tidy-up: prefer return over exit(), fix fallouts 2025-02-28 13:11:41 +01:00
CMakeLists.txt
connect-to.c
cookie_interface.c tidy-up: prefer return over exit(), fix fallouts 2025-02-28 13:11:41 +01:00
crawler.c
debug.c
default-scheme.c
ephiperfifo.c
evhiperfifo.c
externalsocket.c
fileupload.c
ftp-wildcard.c
ftpget.c
ftpgetinfo.c
ftpgetresp.c
ftpsget.c
ftpupload.c
ftpuploadfrommem.c
ftpuploadresume.c
getinfo.c
getinmemory.c
getredirect.c
getreferrer.c
ghiper.c
headerapi.c
hiperfifo.c
href_extractor.c
hsts-preload.c
htmltidy.c
htmltitle.cpp tidy-up: prefer return over exit(), fix fallouts 2025-02-28 13:11:41 +01:00
http2-download.c tidy-up: prefer return over exit(), fix fallouts 2025-02-28 13:11:41 +01:00
http2-pushinmemory.c
http2-serverpush.c
http2-upload.c tidy-up: prefer return over exit(), fix fallouts 2025-02-28 13:11:41 +01:00
http3-present.c
http3.c
http-options.c
http-post.c
httpcustomheader.c
httpput-postfields.c
httpput.c
https.c
imap-append.c
imap-authzid.c
imap-copy.c
imap-create.c
imap-delete.c
imap-examine.c
imap-fetch.c
imap-list.c
imap-lsub.c
imap-multi.c
imap-noop.c
imap-search.c
imap-ssl.c
imap-store.c
imap-tls.c
interface.c
ipv6.c
keepalive.c
localport.c
Makefile.am
Makefile.example
Makefile.inc
maxconnects.c
multi-app.c
multi-debugcallback.c
multi-double.c
multi-event.c
multi-formadd.c
multi-legacy.c
multi-post.c
multi-single.c
multi-uv.c
multithread.c
netrc.c
parseurl.c
persistent.c
pop3-authzid.c
pop3-dele.c
pop3-list.c
pop3-multi.c
pop3-noop.c
pop3-retr.c
pop3-ssl.c
pop3-stat.c
pop3-tls.c
pop3-top.c
pop3-uidl.c
post-callback.c
postinmemory.c
postit2-formadd.c
postit2.c
progressfunc.c
protofeats.c
range.c
README.md
resolve.c
rtsp-options.c
sendrecv.c
sepheaders.c
sessioninfo.c
sftpget.c
sftpuploadresume.c
shared-connection-cache.c
simple.c
simplepost.c
simplessl.c
smooth-gtk-thread.c
smtp-authzid.c
smtp-expn.c
smtp-mail.c
smtp-mime.c
smtp-multi.c
smtp-ssl.c
smtp-tls.c
smtp-vrfy.c
sslbackend.c
synctime.c
threaded-ssl.c
unixsocket.c
url2file.c
urlapi.c
usercertinmem.c
version-check.pl
websocket-cb.c
websocket.c
xmlstream.c

libcurl examples

This directory is for libcurl programming examples. They are meant to show some simple steps on how you can build your own application to take full advantage of libcurl.

If you end up with other small but still useful example sources, please mail them for submission in future packages and on the website.

Building

The Makefile.example is an example Makefile that could be used to build these examples. Just edit the file according to your system and requirements first.

Most examples should build fine using a command line like this:

`curl-config --cc --cflags --libs` -o example-my example.c

Some compilers do not like having the arguments in this order but instead want you do reorganize them like:

`curl-config --cc` -o example-my example.c `curl-config --cflags --libs`

Please do not use the curl.se site as a test target for your libcurl applications/experiments. Even if some of the examples use that site as a URL at some places, it does not mean that the URLs work or that we expect you to actually torture our website with your tests. Thanks.

Examples

Each example source code file is designed to be and work stand-alone and rather self-explanatory. The examples may at times lack the level of error checks you need in a real world, but that is then only for the sake of readability: to make the code smaller and easier to follow.