[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 116/156: examples/sessions.c: removed non-portable funct
From: |
gnunet |
Subject: |
[libmicrohttpd] 116/156: examples/sessions.c: removed non-portable function |
Date: |
Sun, 28 May 2023 17:52:49 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to tag v0.9.77
in repository libmicrohttpd.
commit 89b7c8436e4888bc5fe817b846114e354977cb16
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Fri May 19 13:01:35 2023 +0300
examples/sessions.c: removed non-portable function
---
doc/examples/sessions.c | 95 +++++++++++++++++--------------------------------
1 file changed, 32 insertions(+), 63 deletions(-)
diff --git a/doc/examples/sessions.c b/doc/examples/sessions.c
index db311bd4..3acfd260 100644
--- a/doc/examples/sessions.c
+++ b/doc/examples/sessions.c
@@ -1,11 +1,6 @@
/* Feel free to use this example code in any way
you see fit (Public Domain) */
-/* needed for asprintf */
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE 1
-#endif
-
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -13,48 +8,6 @@
#include <time.h>
#include <microhttpd.h>
-#if defined _WIN32 && ! defined(__MINGW64_VERSION_MAJOR)
-static 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.
*/
@@ -344,14 +297,22 @@ fill_v1_form (const void *cls,
const char *form = cls;
char *reply;
struct MHD_Response *response;
+ int len;
+
+ /* Emulate 'asprintf' */
+ len = snprintf(NULL, 0, form, session->value_1);
+ if (0 > len)
+ return MHD_NO; /* Internal error */
+
+ reply = (char *) malloc (len + 1);
+ if (NULL == reply)
+ return MHD_NO; /* Out-of-memory error */
+
+ if (len != snprintf (reply,
+ form,
+ session->value_1))
+ return MHD_NO; /* printf error */
- if (-1 == asprintf (&reply,
- form,
- session->value_1))
- {
- /* oops */
- return MHD_NO;
- }
/* return static form */
response = MHD_create_response_from_buffer (strlen (reply),
(void *) reply,
@@ -386,15 +347,23 @@ fill_v1_v2_form (const void *cls,
const char *form = cls;
char *reply;
struct MHD_Response *response;
+ int len;
+
+ /* Emulate 'asprintf' */
+ len = snprintf(NULL, 0, form, session->value_1, session->value_2);
+ if (0 > len)
+ return MHD_NO; /* Internal error */
+
+ reply = (char *) malloc (len + 1);
+ if (NULL == reply)
+ return MHD_NO; /* Out-of-memory error */
+
+ if (len != snprintf (reply,
+ form,
+ session->value_1,
+ session->value_2))
+ return MHD_NO; /* printf error */
- if (-1 == asprintf (&reply,
- form,
- session->value_1,
- session->value_2))
- {
- /* oops */
- return MHD_NO;
- }
/* return static form */
response = MHD_create_response_from_buffer (strlen (reply),
(void *) reply,
@@ -448,7 +417,7 @@ not_found_page (const void *cls,
/**
* List of all pages served by this HTTP server.
*/
-static struct Page pages[] = {
+static const struct Page pages[] = {
{ "/", "text/html", &fill_v1_form, MAIN_PAGE },
{ "/2", "text/html", &fill_v1_v2_form, SECOND_PAGE },
{ "/S", "text/html", &serve_simple_form, SUBMIT_PAGE },
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] 93/156: Added more mutes for autoconf compiler warnings, (continued)
- [libmicrohttpd] 93/156: Added more mutes for autoconf compiler warnings, gnunet, 2023/05/28
- [libmicrohttpd] 92/156: bootstrap script: improved portability, gnunet, 2023/05/28
- [libmicrohttpd] 95/156: test_post_form: updated to support the new libcurl API, gnunet, 2023/05/28
- [libmicrohttpd] 104/156: test_quiesce: fixed possible uninitialised var, gnunet, 2023/05/28
- [libmicrohttpd] 101/156: configure: bumped gettext version requirement, gnunet, 2023/05/28
- [libmicrohttpd] 100/156: test_toolarge: fixed reported error description, gnunet, 2023/05/28
- [libmicrohttpd] 108/156: test_client_put_stop: fixed typo in comment, gnunet, 2023/05/28
- [libmicrohttpd] 105/156: Removed redundant autopoint file, gnunet, 2023/05/28
- [libmicrohttpd] 118/156: examples/http_chunked_compression.c: fixed void pointer arithmetic, gnunet, 2023/05/28
- [libmicrohttpd] 126/156: testcurl/https: moved certs variable declaration to the header, gnunet, 2023/05/28
- [libmicrohttpd] 116/156: examples/sessions.c: removed non-portable function,
gnunet <=
- [libmicrohttpd] 132/156: W32 VS projects: unified output and intermediate directories, gnunet, 2023/05/28
- [libmicrohttpd] 133/156: W32 VS projects: disabled specific compiler warning on ARM, gnunet, 2023/05/28
- [libmicrohttpd] 111/156: test_timeout: moved to heavy tests, gnunet, 2023/05/28
- [libmicrohttpd] 97/156: test_put_header_fold: adopted to new libcurl API, gnunet, 2023/05/28
- [libmicrohttpd] 119/156: configure: fixed detection of __FUNCTION__ magic macro, gnunet, 2023/05/28
- [libmicrohttpd] 123/156: test_client_put_stop: muted compiler warnings, gnunet, 2023/05/28
- [libmicrohttpd] 124/156: testcurl/https: removed enforcement of TLS version and cipher, gnunet, 2023/05/28
- [libmicrohttpd] 128/156: websocket_threaded_example: fixed wrong commented-out code, gnunet, 2023/05/28
- [libmicrohttpd] 130/156: test_client_put_stop: fixed typo in diag message, gnunet, 2023/05/28
- [libmicrohttpd] 134/156: W32 VS projects: fixed: define 'WIN32' only on x32 platforms, gnunet, 2023/05/28