From: Viktor Szakats Date: Thu, 28 Nov 2024 13:59:35 +0000 (+0100) Subject: examples: make them compile with compatibility functions disabled (Windows) X-Git-Tag: curl-8_12_0~307 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46093d9e0e0b105e5ca39c9abcd623ec36435faf;p=thirdparty%2Fcurl.git examples: make them compile with compatibility functions disabled (Windows) For MinGW this is `-DNO_OLDNAMES`, with MSVC it is `-D_CRT_DECLARE_NONSTDC_NAMES=0`. There have been some support for this before this patch. After this patch this is extended to all examples. (And also the standalone http/client programs, if here.) Cherry-picked from #15652 Closes #15789 --- diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 3bbc056c0b..6dfb5c53d5 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -34,9 +34,11 @@ #include #ifdef _WIN32 -# define FILENO(fp) _fileno(fp) -#else -# define FILENO(fp) fileno(fp) +#undef stat +#define stat _stat +#undef fstat +#define fstat _fstat +#define fileno _fileno #endif #if LIBCURL_VERSION_NUM < 0x070c03 @@ -98,7 +100,7 @@ int main(int argc, char **argv) /* get the file size of the local file */ fp = fopen(file, "rb"); - fstat(FILENO(fp), &file_info); + fstat(fileno(fp), &file_info); /* In Windows, this inits the Winsock stuff */ curl_global_init(CURL_GLOBAL_ALL); diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 9e3bd84f72..f1e7253ef8 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -30,6 +30,14 @@ #include #include +#ifdef _WIN32 +#undef stat +#define stat _stat +#undef fstat +#define fstat _fstat +#define fileno _fileno +#endif + int main(void) { CURL *curl; diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 462202e6cf..593c33d343 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -31,6 +31,8 @@ #include #ifdef _WIN32 #include +#undef stat +#define stat _stat #else #include #endif diff --git a/docs/examples/http2-upload.c b/docs/examples/http2-upload.c index e804fb76a9..292897c1b9 100644 --- a/docs/examples/http2-upload.c +++ b/docs/examples/http2-upload.c @@ -38,6 +38,11 @@ #include #endif +#ifdef _WIN32 +#undef stat +#define stat _stat +#endif + /* curl stuff */ #include #include diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index ebd2b7696c..f7cffc8114 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -30,6 +30,11 @@ #include #include +#ifdef _WIN32 +#undef stat +#define stat _stat +#endif + /* * This example shows an HTTP PUT operation. PUTs a file given as a command * line argument to the URL also given on the command line. diff --git a/tests/http/clients/hx-download.c b/tests/http/clients/hx-download.c index 94e9d0cbd6..80da0c66a8 100644 --- a/tests/http/clients/hx-download.c +++ b/tests/http/clients/hx-download.c @@ -37,6 +37,10 @@ #include /* getopt() */ #endif +#ifdef _WIN32 +#define strdup _strdup +#endif + #ifndef CURLPIPE_MULTIPLEX #error "too old libcurl, cannot do HTTP/2 server push!" #endif