Skip to content

Commit ad401b6

Browse files
author
grothoff
committed
avoid asprintf
git-svn-id: https://gnunet.org/svn/libmicrohttpd@16060 140774ce-b5e7-0310-ab8b-a85725594a96
1 parent fd7bfdc commit ad401b6

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/examples/post_example.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
* @author Christian Grothoff
2323
*/
2424

25-
/* needed for asprintf */
26-
#define _GNU_SOURCE
27-
28-
2925
#include <stdlib.h>
3026
#include <string.h>
3127
#include <stdio.h>
@@ -319,13 +315,11 @@ fill_v1_form (const void *cls,
319315
char *reply;
320316
struct MHD_Response *response;
321317

322-
if (-1 == asprintf (&reply,
323-
form,
324-
session->value_1))
325-
{
326-
/* oops */
327-
return MHD_NO;
328-
}
318+
reply = malloc (strlen (form) + strlen (session->value_1) + 1);
319+
snprintf (reply,
320+
strlen (form) + strlen (session->value_1) + 1,
321+
form,
322+
session->value_1);
329323
/* return static form */
330324
response = MHD_create_response_from_buffer (strlen (reply),
331325
(void *) reply,
@@ -361,14 +355,11 @@ fill_v1_v2_form (const void *cls,
361355
char *reply;
362356
struct MHD_Response *response;
363357

364-
if (-1 == asprintf (&reply,
365-
form,
366-
session->value_1,
367-
session->value_2))
368-
{
369-
/* oops */
370-
return MHD_NO;
371-
}
358+
reply = malloc (strlen (form) + strlen (session->value_1) + strlen (session->value_2) + 1);
359+
snprintf (reply,
360+
strlen (form) + strlen (session->value_1) + strlen (session->value_2) + 1,
361+
form,
362+
session->value_1);
372363
/* return static form */
373364
response = MHD_create_response_from_buffer (strlen (reply),
374365
(void *) reply,

0 commit comments

Comments
 (0)