From 8e296115313b4fa5bb631a53d2670033a9016603 Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Sat, 8 Jun 2013 19:43:30 -0400 Subject: [PATCH 3/6] Fall back on asprintf if obstack_printf is not available uClibc provides support for obstacks, but does not provide obstack_printf. We check if obstack_printf is available, and if it is not, we fall back on asprintf plus obstack_grow. This is not sufficient on libc systems which do not support obstacks which is not part of POSIX standards. Signed-off-by: Anthony G. Basile --- configure.ac | 3 +++ libcpu/i386_parse.y | 9 +++++++++ src/nm.c | 9 +++++++++ 3 files changed, 21 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index 9d41918..5966453 100644 --- a/configure.ac +++ b/configure.ac @@ -262,6 +262,9 @@ AC_SUBST([argp_LDADD]) dnl Check for __mempcpy AC_CHECK_FUNCS_ONCE([__mempcpy]) +dnl Chekf for obstack_printf +AC_CHECK_FUNCS_ONCE([obstack_printf]) + dnl The directories with content. dnl Documentation. diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y index 689ba22..d567785 100644 --- a/libcpu/i386_parse.y +++ b/libcpu/i386_parse.y @@ -48,6 +48,15 @@ #include +#ifndef HAVE_OBSTACK_PRINTF +# define obstack_printf(x, ...) ({ \ + char *s; \ + int n = asprintf(&s, __VA_ARGS__); \ + obstack_grow(&os, s, n); \ + n; \ +}) +#endif + #define obstack_chunk_alloc xmalloc #define obstack_chunk_free free diff --git a/src/nm.c b/src/nm.c index 7aae84b..18c374a 100644 --- a/src/nm.c +++ b/src/nm.c @@ -47,6 +47,15 @@ #include #include "../libebl/libeblP.h" +/* Fall back on asprintf if we don't have obstack_printf */ +#ifndef HAVE_OBSTACK_PRINTF +# define obstack_printf(x, ...) ({ \ + char *s; \ + int n = asprintf(&s, __VA_ARGS__); \ + obstack_grow(&whereob, s, n); \ + n; \ +}) +#endif /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -- 1.7.8.6