This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 6/7] common: add an alternative implementation for xstrvprintf
- From: Mircea Gherzan <mircea dot gherzan at intel dot com>
- To: tromey at redhat dot com, palves at redhat dot com, jan dot kratochvil at redhat dot com
- Cc: gdb-patches at sourceware dot org, Mircea Gherzan <mircea dot gherzan at intel dot com>
- Date: Thu, 27 Jun 2013 10:43:41 +0200
- Subject: [PATCH 6/7] common: add an alternative implementation for xstrvprintf
- References: <1372322622-3216-1-git-send-email-mircea dot gherzan at intel dot com>
The vasprintf(), used by the current implementation, is a GNU extension.
2013-06-25 Mircea Gherzan <mircea.gherzan@intel.com>
* configure.ac (AC_CHECK_FUNCS): Add vasprintf.
* config.in: Rebuild.
* configure: Rebuild.
* common/common-utils.c (xstrvprintf): Add an alternative
implementation that uses vsnprintf.
Signed-off-by: Mircea Gherzan <mircea.gherzan@intel.com>
---
gdb/common/common-utils.c | 30 ++++++++++++++++++++++++++++++
gdb/config.in | 3 +++
gdb/configure | 2 +-
gdb/configure.ac | 2 +-
4 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c
index 4204abf..e4f1fda 100644
--- a/gdb/common/common-utils.c
+++ b/gdb/common/common-utils.c
@@ -123,6 +123,8 @@ xstrprintf (const char *format, ...)
return ret;
}
+#ifdef HAVE_VASPRINTF
+
char *
xstrvprintf (const char *format, va_list ap)
{
@@ -138,6 +140,34 @@ xstrvprintf (const char *format, va_list ap)
return ret;
}
+#else
+
+char *
+xstrvprintf (const char *format, va_list ap)
+{
+ char *buf;
+ int size;
+ size_t format_len;
+
+ format_len = strlen (format);
+ buf = xmalloc (format_len + 1);
+ size = vsnprintf (buf, format_len + 1, format, ap);
+
+ if (size > (int)format_len)
+ {
+ /* The original size might not be enough. */
+ buf = xrealloc (buf, size + 1);
+ size = vsnprintf (buf, size + 1, format, ap);
+ }
+
+ if (size < 0)
+ internal_error (__FILE__, __LINE__, _("vsnprintf call failed"));
+
+ return buf;
+}
+
+#endif
+
int
xsnprintf (char *str, size_t size, const char *format, ...)
{
diff --git a/gdb/config.in b/gdb/config.in
index 7cd22e3..78e4534 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -554,6 +554,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
+/* Define to 1 if you have the `vasprintf' function. */
+#undef HAVE_VASPRINTF
+
/* Define to 1 if you have the `vfork' function. */
#undef HAVE_VFORK
diff --git a/gdb/configure b/gdb/configure
index 383d634..003e591 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -10178,7 +10178,7 @@ for ac_func in canonicalize_file_name realpath getrusage getuid getgid \
sigaction sigprocmask sigsetmask socketpair syscall \
ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
setrlimit getrlimit posix_madvise waitpid lstat \
- fdwalk pipe2
+ fdwalk pipe2 vasprintf
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 46a97bd..ffd790f 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1180,7 +1180,7 @@ AC_CHECK_FUNCS([canonicalize_file_name realpath getrusage getuid getgid \
sigaction sigprocmask sigsetmask socketpair syscall \
ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
setrlimit getrlimit posix_madvise waitpid lstat \
- fdwalk pipe2])
+ fdwalk pipe2 vasprintf])
AM_LANGINFO_CODESET
# Check the return and argument types of ptrace. No canned test for
--
1.7.12.4