]> git.ipfire.org Git - thirdparty/curl.git/commit
examples: fix compiling with MSVC
authorViktor Szakats <commit@vsz.me>
Fri, 24 May 2024 16:38:32 +0000 (18:38 +0200)
committerViktor Szakats <commit@vsz.me>
Sun, 26 May 2024 20:43:04 +0000 (22:43 +0200)
commitd4b85890555388bec212b75f47a5c1a48705b156
tree441191c825105aba06dde427c1baa34239b2cf03
parent21eb2b55a695babec41ccb3971e5ce3019978bab
examples: fix compiling with MSVC

- `websocket.c`: use `Sleep()` on Windows.
  `sleep()` and `unistd.h` are not available in MSVC.

- `http2-upload.c`: use local `gettimeofday()` implementation when
  compiled with MSVC.
  (Alternate solution is to disable the trace function for MSVC.)
  Public domain code copied and adapted from libssh2:
  https://github.com/libssh2/libssh2/blob/e973493f992313b3be73f51d3f7ca6d52e288558/src/misc.c#L719-L743

- silence compiler warning for deprecated `inet_addr()`.
  Also drop duplicate winsock2 include.
  ```
  curl\docs\examples\externalsocket.c(125,32): error C2220: the following warning is treated as an error [curl\bld\docs\examples\curl-example-externalsocket.vcxproj]
  curl\docs\examples\externalsocket.c(125,32): warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings [curl\bld\docs\examples\curl-example-e
  ```
  Ref: https://github.com/curl/curl/actions/runs/9227337318/job/25389073450#step:4:95

- silence an MSVC compiler warning. This is in conflict with `checksrc`
  rules, so silence the rule in favour of the warning-free C syntax.
  ```
  curl\docs\examples\multi-legacy.c(152,1): error C2220: the following warning is treated as an error [curl\bld\docs\examples\curl-example-multi-legacy.vcxproj]
  curl\docs\examples\multi-legacy.c(152,1): warning C4706: assignment within conditional expression [curl\bld\docs\examples\curl-example-multi-legacy.vcxproj]
  ```
  Ref: https://github.com/curl/curl/actions/runs/9227337318/job/25389073450#step:4:226

- do not use `sys/time.h` and `unistd.h` in Windows builds.
  Some of these includes look unnecessary. Subject to another PR.

Cherry-picked from #13766
Closes #13771
17 files changed:
docs/examples/10-at-a-time.c
docs/examples/externalsocket.c
docs/examples/http2-download.c
docs/examples/http2-pushinmemory.c
docs/examples/http2-serverpush.c
docs/examples/http2-upload.c
docs/examples/multi-app.c
docs/examples/multi-debugcallback.c
docs/examples/multi-double.c
docs/examples/multi-formadd.c
docs/examples/multi-legacy.c
docs/examples/multi-post.c
docs/examples/multi-single.c
docs/examples/persistent.c
docs/examples/sepheaders.c
docs/examples/url2file.c
docs/examples/websocket.c