Explorar el Código

W32 compatibility, also use ISO C instead of POSIX

LRN hace 12 años
padre
commit
aeaea9eda2

+ 4 - 0
doc/examples/basicauthentication.c

@@ -2,8 +2,12 @@
    you see fit (Public Domain) */
 
 #include <sys/types.h>
+#ifndef _WIN32
 #include <sys/select.h>
 #include <sys/socket.h>
+#else
+#include <winsock2.h>
+#endif
 #include <microhttpd.h>
 #include <time.h>
 #include <string.h>

+ 4 - 0
doc/examples/hellobrowser.c

@@ -2,8 +2,12 @@
    you see fit (Public Domain) */
 
 #include <sys/types.h>
+#ifndef _WIN32
 #include <sys/select.h>
 #include <sys/socket.h>
+#else
+#include <winsock2.h>
+#endif
 #include <string.h>
 #include <microhttpd.h>
 #include <stdio.h>

+ 4 - 0
doc/examples/largepost.c

@@ -2,8 +2,12 @@
    you see fit (Public Domain) */
 
 #include <sys/types.h>
+#ifndef _WIN32
 #include <sys/select.h>
 #include <sys/socket.h>
+#else
+#include <winsock2.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

+ 4 - 0
doc/examples/logging.c

@@ -2,8 +2,12 @@
    you see fit (Public Domain) */
 
 #include <sys/types.h>
+#ifndef _WIN32
 #include <sys/select.h>
 #include <sys/socket.h>
+#else
+#include <winsock2.h>
+#endif
 #include <microhttpd.h>
 #include <stdio.h>
 

+ 4 - 0
doc/examples/responseheaders.c

@@ -2,8 +2,12 @@
    you see fit (Public Domain) */
 
 #include <sys/types.h>
+#ifndef _WIN32
 #include <sys/select.h>
 #include <sys/socket.h>
+#else
+#include <winsock2.h>
+#endif
 #include <microhttpd.h>
 #include <time.h>
 #include <sys/stat.h>

+ 45 - 6
doc/examples/sessions.c

@@ -4,7 +4,6 @@
 /* needed for asprintf */
 #define _GNU_SOURCE
 
-
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -12,6 +11,46 @@
 #include <time.h>
 #include <microhttpd.h>
 
+#ifdef _WIN32
+int
+asprintf (char **resultp, const char *format, ...)
+{
+  va_list argptr;
+  char *result = NULL;
+  int len = 0;
+
+  if (format == NULL)
+    return -1;
+
+  va_start (argptr, format);
+
+  len = _vscprintf ((char *) format, argptr);
+  if (len >= 0)
+  {
+    len += 1;
+    result = (char *) malloc (sizeof (char *) * len);
+    if (result != NULL)
+    {
+      int len2 = _vscprintf ((char *) format, argptr);
+      if (len2 != len - 1 || len2 <= 0)
+      {
+        free (result);
+        result = NULL;
+        len = -1;
+      }
+      else
+      {
+        len = len2;
+        if (resultp)
+          *resultp = result;
+      }
+    }
+  }
+  va_end (argptr);
+  return len;
+}
+#endif
+
 /**
  * Invalid method page.
  */
@@ -163,10 +202,10 @@ get_session (struct MHD_Connection *connection)
   snprintf (ret->sid,
 	    sizeof (ret->sid),
 	    "%X%X%X%X",
-	    (unsigned int) random (),
-	    (unsigned int) random (),
-	    (unsigned int) random (),
-	    (unsigned int) random ());
+	    (unsigned int) rand (),
+	    (unsigned int) rand (),
+	    (unsigned int) rand (),
+	    (unsigned int) rand ());
   ret->rc++;  
   ret->start = time (NULL);
   ret->next = sessions;
@@ -691,7 +730,7 @@ main (int argc, char *const *argv)
       return 1;
     }
   /* initialize PRNG */
-  srandom ((unsigned int) time (NULL));
+  srand ((unsigned int) time (NULL));
   d = MHD_start_daemon (MHD_USE_DEBUG,
                         atoi (argv[1]),
                         NULL, NULL, 

+ 4 - 0
doc/examples/simplepost.c

@@ -2,8 +2,12 @@
    you see fit (Public Domain) */
 
 #include <sys/types.h>
+#ifndef _WIN32
 #include <sys/select.h>
 #include <sys/socket.h>
+#else
+#include <winsock2.h>
+#endif
 #include <microhttpd.h>
 #include <stdio.h>
 #include <string.h>

+ 4 - 0
doc/examples/tlsauthentication.c

@@ -2,8 +2,12 @@
    you see fit (Public Domain) */
 
 #include <sys/types.h>
+#ifndef _WIN32
 #include <sys/select.h>
 #include <sys/socket.h>
+#else
+#include <winsock2.h>
+#endif
 #include <microhttpd.h>
 #include <string.h>
 #include <stdio.h>