From 78ea04556f6e4f4d21f3826d2236cdfe2242cd8b Mon Sep 17 00:00:00 2001
From: Sergey Lyubka <valenok@gmail.com>
Date: Mon, 24 Sep 2012 21:25:06 +0100
Subject: [PATCH] Windows build for examples added

---
 examples/Makefile | 14 ++++++++++++++
 examples/upload.c | 14 ++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/examples/Makefile b/examples/Makefile
index 863b80128..94597f393 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -8,3 +8,17 @@ all:
 	  $(CC) $(CFLAGS) post.c ../mongoose.c  $$LIBS $(ADD) -o post;
 	  $(CC) $(CFLAGS) -DUSE_WEBSOCKET websocket.c ../mongoose.c  $$LIBS $(ADD) -o websocket;
 	  $(CC) $(CFLAGS) chat.c ../mongoose.c  $$LIBS $(ADD) -o chat
+
+
+MSVC    = e:/vc6
+CL      = $(MSVC)/bin/cl
+CLFLAGS = /MD /TC /nologo $(DBG) /W3 /DNO_SSL \
+        /I$(MSVC)/include /I.. /Dsnprintf=_snprintf \
+        /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86
+
+windows:
+	$(CL) hello.c ../mongoose.c $(CLFLAGS)
+	$(CL) upload.c ../mongoose.c $(CLFLAGS)
+	$(CL) post.c ../mongoose.c $(CLFLAGS)
+	$(CL) post.c ../mongoose.c $(CLFLAGS)
+	$(CL) /DUSE_WEBSOCKET websocket.c ../mongoose.c $(CLFLAGS)
\ No newline at end of file
diff --git a/examples/upload.c b/examples/upload.c
index dea8cdd41..0111d8d39 100644
--- a/examples/upload.c
+++ b/examples/upload.c
@@ -5,8 +5,18 @@
 #include <string.h>
 #include <fcntl.h>
 #include <stdlib.h>
+#ifdef _WIN32
+#include <windows.h>
+#include <io.h>
+#define strtoll strtol
+typedef __int64 int64_t;
+#define O_CLOEXEC 0
+#define O_EXLOCK 0
+#else 
 #include <inttypes.h>
 #include <unistd.h>
+#endif // !_WIN32
+
 #include "mongoose.h"
 
 // Make sure that form has enctype="multipart/form-data" attribute
@@ -25,7 +35,7 @@ static void handle_file_upload(struct mg_connection *conn) {
   char post_data[16 * 1024], path[999], file_name[1024], mime_type[100],
        buf[BUFSIZ], *eop, *s, *p;
   FILE *fp;
-  long long int cl, written;
+  int64_t cl, written;
   int fd, n, post_data_len;
 
   // Figure out total content length. Return if it is not present or invalid.
@@ -87,7 +97,7 @@ static void handle_file_upload(struct mg_connection *conn) {
     (void) fwrite(p, 1, n, fp);
     written = n;
     while (written < cl &&
-           (n = mg_read(conn, buf, cl - written > (long long) sizeof(buf) ?
+           (n = mg_read(conn, buf, cl - written > (int64_t) sizeof(buf) ?
                         sizeof(buf) : cl - written)) > 0) {
       (void) fwrite(buf, 1, n, fp);
       written += n;
-- 
GitLab