]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
examples: make them compile with compatibility functions disabled (Windows)
authorViktor Szakats <commit@vsz.me>
Thu, 28 Nov 2024 13:59:35 +0000 (14:59 +0100)
committerViktor Szakats <commit@vsz.me>
Fri, 20 Dec 2024 16:56:40 +0000 (17:56 +0100)
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

docs/examples/anyauthput.c
docs/examples/fileupload.c
docs/examples/ftpupload.c
docs/examples/http2-upload.c
docs/examples/httpput.c
tests/http/clients/hx-download.c

index 3bbc056c0b453592c1a7120b450826c0c807b544..6dfb5c53d5a5217e0140adba666ea8249f937d47 100644 (file)
 #include <curl/curl.h>
 
 #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);
index 9e3bd84f72638e22906d20857482754adfef87f9..f1e7253ef8b66383335fc7c71877f57d84678d1b 100644 (file)
 #include <sys/stat.h>
 #include <fcntl.h>
 
+#ifdef _WIN32
+#undef stat
+#define stat _stat
+#undef fstat
+#define fstat _fstat
+#define fileno _fileno
+#endif
+
 int main(void)
 {
   CURL *curl;
index 462202e6cf93d7a3cef36c07f4154e85e198cb3b..593c33d343ac7fe53e3ceee745722e17af4fc444 100644 (file)
@@ -31,6 +31,8 @@
 #include <errno.h>
 #ifdef _WIN32
 #include <io.h>
+#undef stat
+#define stat _stat
 #else
 #include <unistd.h>
 #endif
index e804fb76a97f97f2ee622e52f7429ce749e14824..292897c1b9b4f9824bd31da513c778fffdf85463 100644 (file)
 #include <unistd.h>
 #endif
 
+#ifdef _WIN32
+#undef stat
+#define stat _stat
+#endif
+
 /* curl stuff */
 #include <curl/curl.h>
 #include <curl/mprintf.h>
index ebd2b7696c3325c39d71942c34bfded0fe37e178..f7cffc8114541d49efc380e6f6c16602f4748296 100644 (file)
 #include <sys/stat.h>
 #include <curl/curl.h>
 
+#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.
index 94e9d0cbd6d43b3e00c321e2521f047f2b17a54a..80da0c66a848a7ac85a1d244d849b9aad682438d 100644 (file)
 #include <unistd.h>  /* getopt() */
 #endif
 
+#ifdef _WIN32
+#define strdup _strdup
+#endif
+
 #ifndef CURLPIPE_MULTIPLEX
 #error "too old libcurl, cannot do HTTP/2 server push!"
 #endif