From 10d12e77d5cdffd064719356a87f839225916a4a Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Thu, 13 Jun 2013 10:54:39 -0400 Subject: libc/misc/gnu/obprintf.c: implement obstack_printf and obstack_vprintf This adds a straight forward implementation for obstack_printf and obstack_vprintf on uClibc's already existing obstack_grow and vasprintf. It does not attempt to port over glibc's implementation in terms of _IO_* structs and functions. Signed-off-by: Anthony G. Basile Signed-off-by: Bernhard Reutner-Fischer --- test/malloc/tst-obstack.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/malloc/tst-obstack.c b/test/malloc/tst-obstack.c index 769697f18..1841946c3 100644 --- a/test/malloc/tst-obstack.c +++ b/test/malloc/tst-obstack.c @@ -1,4 +1,8 @@ -/* Test case by Alexandre Duret-Lutz . */ +/* Test case by Alexandre Duret-Lutz . + * test_obstack_printf() added by Anthony G. Basile . + */ + +#include #include #include #include @@ -26,7 +30,7 @@ verbose_free (void *buf) } int -main (void) +test_obstack_alloc (void) { int result = 0; int align = 2; @@ -62,3 +66,39 @@ main (void) return result; } + +int +test_obstack_printf (void) +{ + int result = 0; + int n; + char *s; + struct obstack ob; + + obstack_init (&ob); + + n = obstack_printf (&ob, "%s%d%c", "testing 1 ... 2 ... ", 3, '\n'); + result |= (n != 22); + printf("obstack_printf => %d\n", n); + + n = obstack_printf (&ob, "%s%d%c", "testing 3 ... 2 ... ", 1, '\0'); + result |= (n != 22); + printf("obstack_printf => %d\n", n); + + s = obstack_finish (&ob); + printf("obstack_printf => %s\n", s); + obstack_free (&ob, NULL); + + return result; +} + +int +main (void) +{ + int result = 0; + + result |= test_obstack_alloc(); + result |= test_obstack_printf(); + + return result; +} -- cgit v1.2.3