curl/docs/examples
Viktor Szakats 2a292c3984
build: add Windows CE / CeGCC support, with CI jobs
Make it possible to build curl for Windows CE using the CeGCC toolchain.
With both CMake and autotools, including tests and examples, also in CI.
The build configuration is the default one with Schannel enabled. No
3rd-party dependencies have been tested.

Also revive old code to make Schannel build with Windows CE, including
certificate verification.

Builds have been throughougly tested. But, I've made no functional tests
for this PR. Some parts (esp. file operations, like truncate and seek)
are stubbed out and likely broken as a result. Test servers build, but
they do not work on Windows CE. This patch substitutes `fstat()` calls
with `stat()`, which operate on filenames, not file handles. This may or
may not work and/or may not be secure.

About CeGCC: I used the latest available macOS binary build v0.59.1
r1397 from 2009, in native `mingw32ce` build mode. CeGCC is in effect
MinGW + GCC 4.4.0 + old/classic-mingw Windows headers. It targets
Windows CE v3.0 according to its `_WIN32_WCE` value. It means this PR
restores portions of old/classic-mingw support. It makes the Windows CE
codepath compatible with GCC 4.4.0. It also adds workaround for CMake,
which cannot identify and configure this toolchain out of the box.

Notes:
- CMake doesn't recognize CeGCC/mingw32ce, necessitating tricks as seen
  with Amiga and MS-DOS.
- CMake doesn't set `MINGW` for mingw32ce. Set it and `MINGW32CE`
  manually as a helper variable, in addition to `WINCE` which CMake sets
  based on `CMAKE_SYSTEM_NAME`.
- CMake fails to create an implib for `libcurl.dll`, due to not
  recognizing the platform as a Windowsy one. This patch adds the
  necessary workaround to make it work.
- headers shipping with CeGCC miss some things curl needs for Schannel
  support. Fixed by restoring and renovating code previously deleted
  old-mingw code.
- it's sometime non-trivial to figure out if a fallout is WinCE,
  mingw32ce, old-mingw, or GCC version-specific.
- WinCE is always Unicode. With exceptions: no `wmain`,
  `GetProcAddress()`.
- `_fileno()` is said to convert from `FILE *` to `void *` which is
  a Win32 file `HANDLE`. (This patch doesn't use this, but with further
  effort it probably could be.)
  https://stackoverflow.com/questions/3989545/how-do-i-get-the-file-handle-from-the-fopen-file-structure
- WinCE has no signals, current directory, stdio/CRT file handles, no
  `_get_osfhandle()`, no `errno`, no `errno.h`. Some of this stuff is
  standard C89, yet missing from this platform. Microsoft expects
  Windows CE apps to use Win32 file API and `FILE *` exclusively.
- revived CeGCC here (not tested for this PR):
  https://building.enlyze.com/posts/a-new-windows-ce-x86-compiler-in-2024/

On `UNDER_CE` vs. `_WIN32_WCE`: (This patch settled on `UNDER_CE`)

- A custom VS2008 WinCE toolchain does not set any of these.
  The compiler binaries don't contain these strings, and has no compiler
  option for targeting WinCE, hinting that a vanilla toolchain isn't
  setting any of them either.
- `UNDER_CE` is automatically defined by the CeGCC compiler.
  https://cegcc.sourceforge.net/docs/details.html
- `UNDER_CE` is similar to `_WIN32`, except it's not set automatically
  by all compilers. It's not supposed to have any value, like a version.
  (Though e.g. OpenSSL sets it to a version)
- `_WIN32_WCE` is the CE counterpart of the non-CE `_WIN32_WINNT` macro.
  That does return the targeted Windows CE version.
- `_WIN32_WCE` is not defined by compilers, and relies on a header
  setting it to a default, or the build to set it to the desired target
  version. This is also how `_WIN32_WINNT` works.
- `_WIN32_WCE` default is set by `windef.h` in CeGCC.
- `_WIN32_WCE` isn't set to a default by MSVC Windows CE headers (the
  ones I checked at least).
- CMake sets `_WIN32_WCE=<ver>`, `UNDER_CE`, `WINCE` for MSVC WinCE.
- `_WIN32_WCE` seems more popular in other projects, including CeGCC
  itself. `zlib` is a notable exception amongst curl dependencies,
  which uses `UNDER_CE`.
- Since `_WIN32_WCE` needs "certain" headers to have it defined, it's
  undefined depending on headers included beforehand.
- `curl/curl.h` re-uses `_WIN32_WCE`'s as a self-guard, relying on
  its not-(necessarily)-defined-by-default property:
  25b445e479/include/curl/curl.h (L77)

Toolchain downloads:
- Windows:
  https://downloads.sourceforge.net/cegcc/cegcc/0.59.1/cegcc_mingw32ce_cygwin1.7_r1399.tar.bz2
- macOS Intel:
  https://downloads.sourceforge.net/cegcc/cegcc/0.59.1/cegcc_mingw32ce_snowleopard_r1397.tar.bz2

Closes #15975
2025-02-21 13:56:34 +01:00
..
.checksrc docs/examples/checksrc: don't allow snprintf specifically 2025-01-06 13:49:21 +01:00
.gitignore gitignore: restore explicit lists and fix them 2025-01-28 14:44:35 +01:00
10-at-a-time.c examples: delete unused includes 2024-05-28 00:27:04 +02:00
adddocsref.pl copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
address-scope.c Makefile.mk: drop in favour of autotools and cmake (MS-DOS, AmigaOS3) 2024-12-16 23:20:55 +01:00
altsvc.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
anyauthput.c build: add Windows CE / CeGCC support, with CI jobs 2025-02-21 13:56:34 +01:00
block_ip.c build: add Windows CE / CeGCC support, with CI jobs 2025-02-21 13:56:34 +01:00
cacertinmem.c build: fix compiling with GCC 4.x versions 2025-01-22 11:26:15 +01:00
certinfo.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
chkspeed.c lib/src: white space edits to comply better with code style 2024-09-19 14:59:12 +02:00
CMakeLists.txt msvc: tidy up _CRT_*_NO_DEPRECATE definitions 2025-01-12 00:34:21 +01:00
connect-to.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
cookie_interface.c cmake: separate target for examples, optimize CI, fix fallouts 2024-09-20 23:53:33 +02:00
crawler.c examples/complicated: fix warnings, bump deprecated callback, tidy up 2024-12-20 17:56:35 +01:00
debug.c lib/src: white space edits to comply better with code style 2024-09-19 14:59:12 +02:00
default-scheme.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
ephiperfifo.c examples/complicated: fix warnings, bump deprecated callback, tidy up 2024-12-20 17:56:35 +01:00
evhiperfifo.c examples: use return according to code style 2025-01-13 09:10:58 +01:00
externalsocket.c build: add Windows CE / CeGCC support, with CI jobs 2025-02-21 13:56:34 +01:00
fileupload.c build: add Windows CE / CeGCC support, with CI jobs 2025-02-21 13:56:34 +01:00
ftp-wildcard.c examples: fix/silence -Wsign-conversion 2024-05-11 11:11:32 +02:00
ftpget.c build: fix -Wconversion/-Wsign-conversion warnings 2023-12-20 15:38:45 +00:00
ftpgetinfo.c lib/src: white space edits to comply better with code style 2024-09-19 14:59:12 +02:00
ftpgetresp.c clang-tidy: add to CI, add cmake support, fix fallouts 2024-12-27 13:42:32 +01:00
ftpsget.c build: fix -Wconversion/-Wsign-conversion warnings 2023-12-20 15:38:45 +00:00
ftpupload.c build: add Windows CE / CeGCC support, with CI jobs 2025-02-21 13:56:34 +01:00
ftpuploadfrommem.c tidy-up: OS names 2024-08-04 19:17:45 +02:00
ftpuploadresume.c build: add Windows CE / CeGCC support, with CI jobs 2025-02-21 13:56:34 +01:00
getinfo.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
getinmemory.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
getredirect.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
getreferrer.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
ghiper.c examples/complicated: fix warnings, bump deprecated callback, tidy up 2024-12-20 17:56:35 +01:00
headerapi.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
hiperfifo.c examples: use return according to code style 2025-01-13 09:10:58 +01:00
href_extractor.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
hsts-preload.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
htmltidy.c lib/src: white space edits to comply better with code style 2024-09-19 14:59:12 +02:00
htmltitle.cpp examples/complicated: fix warnings, bump deprecated callback, tidy up 2024-12-20 17:56:35 +01:00
http2-download.c build: add Windows CE / CeGCC support, with CI jobs 2025-02-21 13:56:34 +01:00
http2-pushinmemory.c examples: delete unused includes 2024-05-28 00:27:04 +02:00
http2-serverpush.c cmake: separate target for examples, optimize CI, fix fallouts 2024-09-20 23:53:33 +02:00
http2-upload.c build: add Windows CE / CeGCC support, with CI jobs 2025-02-21 13:56:34 +01:00
http3-present.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
http3.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
http-options.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
http-post.c tidy-up: OS names 2024-08-04 19:17:45 +02:00
httpcustomheader.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
httpput-postfields.c tidy-up: misc 2024-12-24 01:27:26 +01:00
httpput.c clang-tidy: add to CI, add cmake support, fix fallouts 2024-12-27 13:42:32 +01:00
https.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
imap-append.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
imap-authzid.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
imap-copy.c examples: use present tense in comments 2024-02-27 16:19:43 +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 examples: use present tense in comments 2024-02-27 16:19:43 +01:00
imap-list.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
imap-lsub.c docs: remove use of the word 'very' 2023-09-07 22:52:07 +02:00
imap-multi.c examples: use present tense in comments 2024-02-27 16:19:43 +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 examples: use present tense in comments 2024-02-27 16:19:43 +01:00
imap-store.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
imap-tls.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
interface.c docs/examples/interface.c: show CURLOPT_INTERFACE use 2023-10-30 12:45:34 +01:00
ipv6.c examples/ipv6.c: new example showing IPv6-only internet transfer 2024-01-10 09:33:03 +01:00
keepalive.c tcpkeepalive: add CURLOPT_TCP_KEEPCNT and --keepalive-cnt 2024-06-12 09:31:17 +02:00
localport.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
Makefile.am tidy-up: delete, comment or scope C macros reported unused 2025-02-14 10:37:14 +01:00
Makefile.example tidy-up: adjust casing of project names 2024-07-12 13:56:16 +02:00
Makefile.inc tidy-up: .gitignore lines mostly 2025-01-27 20:59:46 +01:00
maxconnects.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
multi-app.c docs: use lowercase curl and libcurl 2025-01-02 17:15:54 +01:00
multi-debugcallback.c lib/src: white space edits to comply better with code style 2024-09-19 14:59:12 +02:00
multi-double.c examples: delete unused includes 2024-05-28 00:27:04 +02:00
multi-event.c examples/complicated: fix warnings, bump deprecated callback, tidy up 2024-12-20 17:56:35 +01:00
multi-formadd.c build: tidy up deprecation suppression, enable warnings for clang 2024-09-21 00:59:52 +02:00
multi-legacy.c docs: use lowercase curl and libcurl 2025-01-02 17:15:54 +01:00
multi-post.c examples: delete unused includes 2024-05-28 00:27:04 +02:00
multi-single.c examples: delete unused includes 2024-05-28 00:27:04 +02:00
multi-uv.c examples/complicated: fix warnings, bump deprecated callback, tidy up 2024-12-20 17:56:35 +01:00
multithread.c examples/complicated: fix warnings, bump deprecated callback, tidy up 2024-12-20 17:56:35 +01:00
netrc.c examples/netrc.c: add 2024-01-10 09:33:06 +01:00
parseurl.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
persistent.c examples: delete unused includes 2024-05-28 00:27:04 +02:00
pop3-authzid.c examples: use present tense in comments 2024-02-27 16:19:43 +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 examples: use present tense in comments 2024-02-27 16:19:43 +01:00
pop3-multi.c examples: use present tense in comments 2024-02-27 16:19:43 +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 examples: use present tense in comments 2024-02-27 16:19:43 +01:00
pop3-ssl.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
pop3-stat.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
pop3-tls.c examples: use present tense in comments 2024-02-27 16:19:43 +01: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 tidy-up: OS names 2024-08-04 19:17:45 +02:00
postinmemory.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
postit2-formadd.c build: tidy up deprecation suppression, enable warnings for clang 2024-09-21 00:59:52 +02:00
postit2.c examples: use present tense in comments 2024-02-27 16:19:43 +01: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
range.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
README.md GHA: silence proselint warnings and an error 2024-10-15 16:44:17 +02:00
resolve.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
rtsp-options.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
sendrecv.c build: fix compiling with GCC 4.x versions 2025-01-22 11:26:15 +01:00
sepheaders.c examples: delete unused includes 2024-05-28 00:27:04 +02:00
sessioninfo.c examples/complicated: fix warnings, bump deprecated callback, tidy up 2024-12-20 17:56:35 +01:00
sftpget.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
sftpuploadresume.c build: add Windows CE / CeGCC support, with CI jobs 2025-02-21 13:56:34 +01:00
shared-connection-cache.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
simple.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
simplepost.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
simplessl.c docs: use valid example domain names 2025-02-09 00:17:05 +01:00
smooth-gtk-thread.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
smtp-authzid.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
smtp-expn.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
smtp-mail.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
smtp-mime.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
smtp-multi.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
smtp-ssl.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
smtp-tls.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
smtp-vrfy.c examples: use present tense in comments 2024-02-27 16:19:43 +01:00
sslbackend.c docs: use CURLSSLBACKEND_NONE 2023-09-21 14:15:03 +02:00
synctime.c tidy-up: drop parenthesis around return expression 2025-01-14 12:11:42 +01:00
threaded-ssl.c examples/complicated: fix warnings, bump deprecated callback, tidy up 2024-12-20 17:56:35 +01:00
unixsocket.c tidy-up: OS names 2024-08-04 19:17:45 +02:00
url2file.c examples: delete unused includes 2024-05-28 00:27:04 +02:00
urlapi.c examples: make use of CURLOPT_(REDIR_|)PROTOCOLS_STR 2023-06-18 11:09:13 +02:00
usercertinmem.c build: fix compiling with GCC 4.x versions 2025-01-22 11:26:15 +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 examples: use present tense in comments 2024-02-27 16:19:43 +01:00
websocket.c build: fix MSVC UWP builds 2024-11-28 14:24:03 +01:00
xmlstream.c examples/complicated: fix warnings, bump deprecated callback, tidy up 2024-12-20 17:56:35 +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-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.