From 83049ca9ad0d39a5795b586b76f954748a3de316 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Mon, 10 Oct 2011 00:52:08 +0300 Subject: Added asprintf wrapper --- src/xine-utils/utils.c | 12 ++++++++++++ src/xine-utils/xineutils.h | 8 ++++++++ 2 files changed, 20 insertions(+) (limited to 'src') diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index 3d21a2935..82cf5c0d4 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -706,6 +706,18 @@ char *xine_strcat_realloc (char **dest, char *append) return newstr; } +char *_x_asprintf(const char *format, ...) +{ + va_list ap; + char *buf = NULL; + + va_start (ap, format); + if (vasprintf (&buf, format, ap) < 0) + buf = NULL; + va_end (ap); + + return buf; +} int _x_set_file_close_on_exec(int fd) { diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index d0946e471..5b16e6e3c 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -215,6 +215,14 @@ void xine_strdupa(char *dest, char *src) XINE_PROTECTED XINE_DEPRECATED; */ char *xine_strcat_realloc (char **dest, char *append) XINE_PROTECTED; +/** + * asprintf wrapper + * allocate a string large enough to hold the output, and return a pointer to + * it. This pointer should be passed to free when it is no longer needed. + * return NULL on error. + */ +char *_x_asprintf(const char *format, ...) XINE_PROTECTED XINE_MALLOC XINE_FORMAT_PRINTF(1, 2); + /** * opens a file, ensuring that the descriptor will be closed * automatically after a fork/execute. -- cgit v1.2.3