- `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
int still_alive = 1;
curl_multi_perform(cm, &still_alive);
- while((msg = curl_multi_info_read(cm, &msgs_left))) {
+ /* !checksrc! disable EQUALSNULL 1 */
+ while((msg = curl_multi_info_read(cm, &msgs_left)) != NULL) {
if(msg->msg == CURLMSG_DONE) {
char *url;
CURL *e = msg->easy_handle;
* Pass in a custom socket for libcurl to use.
* </DESC>
*/
+#ifdef _WIN32
+#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
+#define _WINSOCK_DEPRECATED_NO_WARNINGS /* for inet_addr() */
+#endif
+#endif
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <curl/curl.h>
#ifdef _WIN32
-#include <winsock2.h>
#define close closesocket
#else
#include <sys/types.h> /* socket types */
#include <sys/socket.h> /* socket definitions */
#include <netinet/in.h>
-#include <arpa/inet.h> /* inet (3) functions */
+#include <arpa/inet.h> /* inet (3) functions */
#include <unistd.h> /* misc. Unix functions */
#endif
#include <errno.h>
/* somewhat unix-specific */
+#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
+#endif
/* curl stuff */
#include <curl/curl.h>
#include <string.h>
/* somewhat unix-specific */
+#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
+#endif
/* curl stuff */
#include <curl/curl.h>
#include <string.h>
/* somewhat unix-specific */
+#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
+#endif
/* curl stuff */
#include <curl/curl.h>
#include <errno.h>
/* somewhat unix-specific */
+#ifndef _MSC_VER
#include <sys/time.h>
#include <unistd.h>
+#endif
/* curl stuff */
#include <curl/curl.h>
#define NUM_HANDLES 1000
+#ifdef _MSC_VER
+#define gettimeofday(a, b) my_gettimeofday((a), (b))
+int my_gettimeofday(struct timeval *tp, void *tzp)
+{
+ (void)tzp;
+ if(tp) {
+ /* Offset between 1601-01-01 and 1970-01-01 in 100 nanosec units */
+ #define _WIN32_FT_OFFSET (116444736000000000)
+ union {
+ CURL_TYPEOF_CURL_OFF_T ns100; /* time since 1 Jan 1601 in 100ns units */
+ FILETIME ft;
+ } _now;
+ GetSystemTimeAsFileTime(&_now.ft);
+ tp->tv_usec = (long)((_now.ns100 / 10) % 1000000);
+ tp->tv_sec = (long)((_now.ns100 - _WIN32_FT_OFFSET) / 10000000);
+ }
+ return 0;
+}
+#endif
+
struct input {
FILE *in;
size_t bytes_read; /* count up */
#include <string.h>
/* somewhat unix-specific */
+#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
+#endif
/* curl stuff */
#include <curl/curl.h>
break;
}
/* See how the transfers went */
- while((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
+ /* !checksrc! disable EQUALSNULL 1 */
+ while((msg = curl_multi_info_read(multi_handle, &msgs_left)) != NULL) {
if(msg->msg == CURLMSG_DONE) {
int idx;
#include <string.h>
/* somewhat unix-specific */
+#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
+#endif
/* curl stuff */
#include <curl/curl.h>
#include <string.h>
/* somewhat unix-specific */
+#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
+#endif
/* curl stuff */
#include <curl/curl.h>
#include <stdio.h>
#include <string.h>
+#ifndef _WIN32
#include <sys/time.h>
+#endif
#include <curl/curl.h>
#include <string.h>
/* somewhat unix-specific */
+#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
+#endif
/* curl stuff */
#include <curl/curl.h>
}
/* See how the transfers went */
- while((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
+ /* !checksrc! disable EQUALSNULL 1 */
+ while((msg = curl_multi_info_read(multi_handle, &msgs_left)) != NULL) {
if(msg->msg == CURLMSG_DONE) {
int idx;
#include <stdio.h>
#include <string.h>
+#ifndef _WIN32
#include <sys/time.h>
+#endif
#include <curl/curl.h>
#include <string.h>
/* somewhat unix-specific */
+#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
+#endif
/* curl stuff */
#include <curl/curl.h>
* </DESC>
*/
#include <stdio.h>
+#ifndef _WIN32
#include <unistd.h>
+#endif
+
#include <curl/curl.h>
int main(void)
*/
#include <stdio.h>
#include <stdlib.h>
+#ifndef _WIN32
#include <unistd.h>
+#endif
#include <curl/curl.h>
*/
#include <stdio.h>
#include <stdlib.h>
+#ifndef _WIN32
#include <unistd.h>
+#endif
#include <curl/curl.h>
*/
#include <stdio.h>
#include <string.h>
+#ifdef _WIN32
+#include <windows.h>
+#define sleep(s) Sleep((DWORD)(s))
+#else
#include <unistd.h>
+#endif
+
#include <curl/curl.h>
static int ping(CURL *curl, const char *send_payload)