diff options
author | Petri Hintukainen <phintuka@users.sourceforge.net> | 2011-10-10 00:52:08 +0300 |
---|---|---|
committer | Petri Hintukainen <phintuka@users.sourceforge.net> | 2011-10-10 00:52:08 +0300 |
commit | 83049ca9ad0d39a5795b586b76f954748a3de316 (patch) | |
tree | 3e4697c79d570f079e1d28573d7fa47b9edb2b66 /src | |
parent | 68a893cefd56a81ff3af304cda6ee897a1506ed3 (diff) | |
download | xine-lib-83049ca9ad0d39a5795b586b76f954748a3de316.tar.gz xine-lib-83049ca9ad0d39a5795b586b76f954748a3de316.tar.bz2 |
Added asprintf wrapper
Diffstat (limited to 'src')
-rw-r--r-- | src/xine-utils/utils.c | 12 | ||||
-rw-r--r-- | src/xine-utils/xineutils.h | 8 |
2 files changed, 20 insertions, 0 deletions
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 @@ -216,6 +216,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. */ |