curl/docs/examples
Viktor Szakats 3829759bd0
build: enable missing OpenSSF-recommended warnings, with fixes
https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html
as of 2023-11-29 [1].

Enable new recommended warnings (except `-Wsign-conversion`):

- enable `-Wformat=2` for clang (in both cmake and autotools).
- add `CURL_PRINTF()` internal attribute and mark functions accepting
  printf arguments with it. This is a copy of existing
  `CURL_TEMP_PRINTF()` but using `__printf__` to make it compatible
  with redefinting the `printf` symbol:
  https://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_5.html#SEC94
- fix `CURL_PRINTF()` and existing `CURL_TEMP_PRINTF()` for
  mingw-w64 and enable it on this platform.
- enable `-Wimplicit-fallthrough`.
- enable `-Wtrampolines`.
- add `-Wsign-conversion` commented with a FIXME.
- cmake: enable `-pedantic-errors` the way we do it with autotools.
  Follow-up to d5c0351055 #2747
- lib/curl_trc.h: use `CURL_FORMAT()`, this also fixes it to enable format
  checks. Previously it was always disabled due to the internal `printf`
  macro.

Fix them:

- fix bug where an `set_ipv6_v6only()` call was missed in builds with
  `--disable-verbose` / `CURL_DISABLE_VERBOSE_STRINGS=ON`.
- add internal `FALLTHROUGH()` macro.
- replace obsolete fall-through comments with `FALLTHROUGH()`.
- fix fallthrough markups: Delete redundant ones (showing up as
  warnings in most cases). Add missing ones. Fix indentation.
- silence `-Wformat-nonliteral` warnings with llvm/clang.
- fix one `-Wformat-nonliteral` warning.
- fix new `-Wformat` and `-Wformat-security` warnings.
- fix `CURL_FORMAT_SOCKET_T` value for mingw-w64. Also move its
  definition to `lib/curl_setup.h` allowing use in `tests/server`.
- lib: fix two wrongly passed string arguments in log outputs.
  Co-authored-by: Jay Satiro
- fix new `-Wformat` warnings on mingw-w64.

[1] 56c0fde389/docs/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C%2B%2B.md

Closes #12489
2023-12-16 13:12:37 +00:00
..
.checksrc checksrc: ban gmtime/localtime 2020-07-28 23:51:17 +02:00
.gitignore copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
10-at-a-time.c windows: use built-in _WIN32 macro to detect Windows 2023-11-22 15:42:25 +00:00
adddocsref.pl copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
altsvc.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
anyauthput.c windows: use built-in _WIN32 macro to detect Windows 2023-11-22 15:42:25 +00:00
cacertinmem.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
certinfo.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
chkspeed.c build: enable missing OpenSSF-recommended warnings, with fixes 2023-12-16 13:12:37 +00:00
connect-to.c misc: fix various typos 2023-08-01 14:09:32 +02:00
cookie_interface.c windows: use built-in _WIN32 macro to detect Windows 2023-11-22 15:42:25 +00:00
crawler.c example/crawler: make it use a few more options 2023-06-19 09:06:41 +02:00
debug.c build: enable missing OpenSSF-recommended warnings, with fixes 2023-12-16 13:12:37 +00:00
default-scheme.c example/default-scheme: set the default scheme for schemeless URLs 2023-06-18 23:37:48 +02:00
ephiperfifo.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
evhiperfifo.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
externalsocket.c windows: use built-in _WIN32 macro to detect Windows 2023-11-22 15:42:25 +00:00
fileupload.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
ftp-wildcard.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
ftpget.c docs: rewrite to present tense 2023-08-23 23:26:10 +02:00
ftpgetinfo.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
ftpgetresp.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
ftpsget.c docs: rewrite to present tense 2023-08-23 23:26:10 +02:00
ftpupload.c windows: use built-in _WIN32 macro to detect Windows 2023-11-22 15:42:25 +00:00
ftpuploadfrommem.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
ftpuploadresume.c examples/ftpuploadresume.c: add use of CURLOPT_ACCEPTTIMEOUT_MS 2023-06-08 23:37:43 +02:00
getinfo.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
getinmemory.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
getredirect.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
getreferrer.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
ghiper.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
headerapi.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
hiperfifo.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
href_extractor.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
hsts-preload.c example/hsts-preload: show one way to HSTS preload 2023-06-18 23:35:40 +02:00
htmltidy.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
htmltitle.cpp misc: fix spelling mistakes 2023-05-23 10:42:09 +02:00
http2-download.c build: enable missing OpenSSF-recommended warnings, with fixes 2023-12-16 13:12:37 +00:00
http2-pushinmemory.c docs: rewrite to present tense 2023-08-23 23:26:10 +02:00
http2-serverpush.c build: enable missing OpenSSF-recommended warnings, with fixes 2023-12-16 13:12:37 +00:00
http2-upload.c build: enable missing OpenSSF-recommended warnings, with fixes 2023-12-16 13:12:37 +00:00
http3-present.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
http3.c examples/http3.c: use CURL_HTTP_VERSION_3 2023-02-27 15:11:13 +01:00
http-options.c examples/http-options: show how to send "OPTIONS *" 2023-06-18 11:10:23 +02:00
http-post.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
httpcustomheader.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
httpput-postfields.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
httpput.c misc: fix spelling mistakes 2023-05-23 10:42:09 +02:00
https.c examples/https.c: use CURLOPT_CA_CACHE_TIMEOUT 2023-06-11 00:17:41 +02:00
imap-append.c docs: use a space after RFC when spelling out RFC numbers 2023-07-09 19:13:33 +02:00
imap-authzid.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-copy.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-create.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-delete.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-examine.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-fetch.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-list.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-lsub.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
imap-multi.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-noop.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-search.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-ssl.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
imap-store.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-tls.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
interface.c docs/examples/interface.c: show CURLOPT_INTERFACE use 2023-10-30 12:45:34 +01:00
ipv6.c windows: use built-in _WIN32 macro to detect Windows 2023-11-22 15:42:25 +00:00
keepalive.c docs/example/keepalive.c: show TCP keep-alive options 2023-11-01 10:57:15 +01:00
localport.c docs/example/localport.c: show off CURLOPT_LOCALPORT 2023-10-30 12:49:00 +01:00
Makefile.am copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
Makefile.example docs: rewrite to present tense 2023-08-23 23:26:10 +02:00
Makefile.inc examples/rtsp-options.c: add 2023-12-04 22:35:38 +01:00
Makefile.mk Makefile.mk: drop Windows support 2023-12-16 13:12:22 +00:00
maxconnects.c example/maxconnects: set maxconnect example 2023-07-11 20:13:25 +02:00
multi-app.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
multi-debugcallback.c build: enable missing OpenSSF-recommended warnings, with fixes 2023-12-16 13:12:37 +00:00
multi-double.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
multi-event.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
multi-formadd.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
multi-legacy.c lib: fix conversion warnings with gcc on macOS 2023-05-21 14:02:31 +02:00
multi-post.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
multi-single.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
multi-uv.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
multithread.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
parseurl.c checksrc: disallow spaces before labels 2023-05-18 20:45:04 +02:00
persistent.c docs: rewrite to present tense 2023-08-23 23:26:10 +02:00
pop3-authzid.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
pop3-dele.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
pop3-list.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
pop3-multi.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
pop3-noop.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
pop3-retr.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
pop3-ssl.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
pop3-stat.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
pop3-tls.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
pop3-top.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
pop3-uidl.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
post-callback.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
postinmemory.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
postit2-formadd.c docs: use a space after RFC when spelling out RFC numbers 2023-07-09 19:13:33 +02:00
postit2.c docs: use a space after RFC when spelling out RFC numbers 2023-07-09 19:13:33 +02:00
progressfunc.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
protofeats.c docs/examples/protofeats.c: Outputs all protocols and features 2023-04-18 08:10:27 +02:00
README.md copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
resolve.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
rtsp-options.c examples/rtsp-options.c: add 2023-12-04 22:35:38 +01:00
sendrecv.c lib: fix conversion warnings with gcc on macOS 2023-05-21 14:02:31 +02:00
sepheaders.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
sessioninfo.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
sftpget.c docs: rewrite to present tense 2023-08-23 23:26:10 +02:00
sftpuploadresume.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
shared-connection-cache.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
simple.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
simplepost.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
simplessl.c spelling: fix codespell 2.2.6 typos 2023-10-03 21:37:56 +00:00
smooth-gtk-thread.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
smtp-authzid.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
smtp-expn.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
smtp-mail.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
smtp-mime.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
smtp-multi.c docs: use a space after RFC when spelling out RFC numbers 2023-07-09 19:13:33 +02:00
smtp-ssl.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
smtp-tls.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
smtp-vrfy.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
sslbackend.c docs: use CURLSSLBACKEND_NONE 2023-09-21 14:15:03 +02:00
synctime.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
threaded-ssl.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unixsocket.c examples/unixsocket.c: example using CURLOPT_UNIX_SOCKET_PATH 2023-06-08 23:36:55 +02:00
url2file.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
urlapi.c examples: make use of CURLOPT_(REDIR_|)PROTOCOLS_STR 2023-06-18 11:09:13 +02:00
usercertinmem.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
version-check.pl copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
websocket-cb.c ws: make the curl_ws_meta() return pointer a const 2023-06-07 23:37:21 +02:00
websocket.c ws: fix spelling mistakes in examples and tests 2023-09-03 18:01:58 +02:00
xmlstream.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00

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 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 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.