libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 42b4f5332288558cd477a7b89a8b91cc035e3709
parent eba63b9e6f6eaf2ed765bbff0934879fff363edd
Author: Evgeny Grin <k2k@drgrin.dev>
Date:   Fri,  2 May 2025 19:48:25 +0300

demo.c: improved portability

Diffstat:
Msrc/examples2/demo.c | 50+++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 39 insertions(+), 11 deletions(-)

diff --git a/src/examples2/demo.c b/src/examples2/demo.c @@ -57,9 +57,13 @@ #endif #ifndef PATH_MAX +# ifdef MAX_PATH +# define PATH_MAX MAX_PATH +# else /* Some platforms (namely: GNU Hurd) do no define PATH_MAX. As it is only example for MHD, just use reasonable value for PATH_MAX. */ -#define PATH_MAX 16384 +# define PATH_MAX 16384 +# endif #endif /** @@ -78,6 +82,26 @@ #endif /* MHD_HAVE_LIBMAGIC */ +#ifdef HAVE_STRDUP +# define my_strdup(str) strdup ((str)) +#else +static char * +my_strdup (const char *str) +{ + size_t sz; + char *str_copy; + + sz = strlen (str); + str_copy = malloc (sz); + if (NULL != str_copy) + memcpy (str_copy, str, sz); + return str_copy; +} + + +#endif + + /** * Page returned for file-not-found. */ @@ -577,7 +601,7 @@ stream_reader (struct MHD_Request *req, return MHD_upload_action_from_response (req, request_refused_response); } - uc->filename = strdup (filename->cstr); + uc->filename = my_strdup (filename->cstr); } if (NULL == uc->filename) { @@ -678,7 +702,7 @@ handle_full_upload (void *cls, uc->error_file = true; return MHD_NO; } - uc->filename = strdup (data->filename.cstr); + uc->filename = my_strdup (data->filename.cstr); fd = mkstemp (uc->tmpname); if (-1 == fd) { @@ -965,17 +989,21 @@ generate_page (void *cls, if (NULL != ldot) { - if (0 == strcasecmp (ldot, - ".html")) + if ((0 == strcmp (ldot, + ".html")) + || (0 == strcmp (ldot, + ".htm")) + || (0 == strcmp (ldot, + ".HTML"))) mime = "text/html"; - if (0 == strcasecmp (ldot, - ".css")) + if (0 == strcmp (ldot, + ".css")) mime = "text/css"; - if (0 == strcasecmp (ldot, - ".css3")) + if (0 == strcmp (ldot, + ".css3")) mime = "text/css"; - if (0 == strcasecmp (ldot, - ".js")) + if (0 == strcmp (ldot, + ".js")) mime = "application/javascript"; } }