[PATCH] libc/misc/gnu/obprintf.c: implement obstack_printf and obstack_vprintf

Anthony G. Basile basile at opensource.dyc.edu
Tue Jun 11 14:25:44 UTC 2013


From: "Anthony G. Basile" <blueness at gentoo.org>

This adds a straight forward implemenatation 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 at gentoo.org>
---
 include/stdio.h           |    2 +-
 libc/misc/gnu/Makefile.in |    2 +-
 libc/misc/gnu/obprintf.c  |   35 +++++++++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 libc/misc/gnu/obprintf.c

diff --git a/include/stdio.h b/include/stdio.h
index e0006d2..94d38ee 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -854,7 +854,7 @@ extern char *cuserid (char *__s);
 #endif /* Use X/Open, but not issue 6.  */
 
 
-#if 0 /* def	__USE_GNU uClibc note: not supported */
+#ifdef	__USE_GNU
 struct obstack;			/* See <obstack.h>.  */
 
 /* Write formatted output to an obstack.  */
diff --git a/libc/misc/gnu/Makefile.in b/libc/misc/gnu/Makefile.in
index 429b471..0da7605 100644
--- a/libc/misc/gnu/Makefile.in
+++ b/libc/misc/gnu/Makefile.in
@@ -8,7 +8,7 @@
 subdirs += libc/misc/gnu
 
 #XXX: add UCLIBC_HAS_OBSTACK
-CSRC-y := obstack.c
+CSRC-y := obstack.c obprintf.c
 
 MISC_GNU_DIR := $(top_srcdir)libc/misc/gnu
 MISC_GNU_OUT := $(top_builddir)libc/misc/gnu
diff --git a/libc/misc/gnu/obprintf.c b/libc/misc/gnu/obprintf.c
new file mode 100644
index 0000000..c80925d
--- /dev/null
+++ b/libc/misc/gnu/obprintf.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2013 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#ifdef _LIBC
+# include <obstack.h>
+#else
+# include "obstack.h"
+#endif
+
+int
+_obstack_vprintf (struct obstack *obstack, const char *format, va_list args)
+{
+  int n;
+  char *s;
+  n = vasprintf(&s, format, args);
+  obstack_grow(obstack, s, n);
+  return n;
+}
+weak_alias (_obstack_vprintf, obstack_vprintf)
+
+int
+_obstack_printf (struct obstack *obstack, const char *format, ...)
+{
+  int n;
+  va_list ap;
+  va_start (ap, format);
+  n = _obstack_vprintf (obstack, format, ap);
+  va_end (ap);
+  return n;
+}
+weak_alias (_obstack_printf, obstack_printf)
-- 
1.7.8.6



More information about the uClibc mailing list