libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit aeaea9eda26ce82e1ea2d88e0847d1a79f1ae1a9
parent 05a6e239a353f9761bdfb37b7d87cfed1d7836fe
Author: LRN <lrn1986@gmail.com>
Date:   Tue, 23 Apr 2013 11:38:09 +0000

W32 compatibility, also use ISO C instead of POSIX


Diffstat:
Mdoc/examples/basicauthentication.c | 4++++
Mdoc/examples/hellobrowser.c | 4++++
Mdoc/examples/largepost.c | 4++++
Mdoc/examples/logging.c | 4++++
Mdoc/examples/responseheaders.c | 4++++
Mdoc/examples/sessions.c | 51+++++++++++++++++++++++++++++++++++++++++++++------
Mdoc/examples/simplepost.c | 4++++
Mdoc/examples/tlsauthentication.c | 4++++
8 files changed, 73 insertions(+), 6 deletions(-)

diff --git a/doc/examples/basicauthentication.c b/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> diff --git a/doc/examples/hellobrowser.c b/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> diff --git a/doc/examples/largepost.c b/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> diff --git a/doc/examples/logging.c b/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> diff --git a/doc/examples/responseheaders.c b/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> diff --git a/doc/examples/sessions.c b/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, diff --git a/doc/examples/simplepost.c b/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> diff --git a/doc/examples/tlsauthentication.c b/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>