libmicrohttpd

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

commit 0216a0f9b312a7dbfd4b6d0919fcb7c3d9f93c71
parent 0601a3bf713a1f196927f7a381cce56ebbf8aa04
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 18 Jul 2011 06:46:18 +0000

avoid asprintf

Diffstat:
Msrc/examples/post_example.c | 29++++++++++-------------------
1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/src/examples/post_example.c b/src/examples/post_example.c @@ -22,10 +22,6 @@ * @author Christian Grothoff */ -/* needed for asprintf */ -#define _GNU_SOURCE - - #include <stdlib.h> #include <string.h> #include <stdio.h> @@ -319,13 +315,11 @@ fill_v1_form (const void *cls, char *reply; struct MHD_Response *response; - if (-1 == asprintf (&reply, - form, - session->value_1)) - { - /* oops */ - return MHD_NO; - } + reply = malloc (strlen (form) + strlen (session->value_1) + 1); + snprintf (reply, + strlen (form) + strlen (session->value_1) + 1, + form, + session->value_1); /* return static form */ response = MHD_create_response_from_buffer (strlen (reply), (void *) reply, @@ -361,14 +355,11 @@ fill_v1_v2_form (const void *cls, char *reply; struct MHD_Response *response; - if (-1 == asprintf (&reply, - form, - session->value_1, - session->value_2)) - { - /* oops */ - return MHD_NO; - } + reply = malloc (strlen (form) + strlen (session->value_1) + strlen (session->value_2) + 1); + snprintf (reply, + strlen (form) + strlen (session->value_1) + strlen (session->value_2) + 1, + form, + session->value_1); /* return static form */ response = MHD_create_response_from_buffer (strlen (reply), (void *) reply,