diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2013-06-13 10:54:39 -0400 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2013-06-14 10:44:08 +0200 |
commit | 10d12e77d5cdffd064719356a87f839225916a4a (patch) | |
tree | 0e367602e34de44b29411856930fe9d2930b5c6d /test | |
parent | f143f920694cec922ed2ac4082aab223acc413df (diff) |
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 <blueness@gentoo.org>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/malloc/tst-obstack.c | 44 |
1 files changed, 42 insertions, 2 deletions
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 <duret_g@epita.fr>. */ +/* Test case by Alexandre Duret-Lutz <duret_g@epita.fr>. + * test_obstack_printf() added by Anthony G. Basile <blueness.gentoo.org>. + */ + +#include <features.h> #include <obstack.h> #include <stdint.h> #include <stdio.h> @@ -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; +} |