aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/avstring.c
diff options
context:
space:
mode:
authorClément Bœsch <ubitux@gmail.com>2011-09-03 19:51:28 +0200
committerClément Bœsch <ubitux@gmail.com>2011-09-04 09:37:41 +0200
commit61e2e2969127e4cb8e0d32151fed3e03515fe436 (patch)
tree72ed060de80329fb6f8891582584779498061659 /libavutil/avstring.c
parent1889c6724a449b2e4826612d3b72efc76dbfb713 (diff)
downloadffmpeg-61e2e2969127e4cb8e0d32151fed3e03515fe436.tar.gz
av_string: add av_asprintf().
Diffstat (limited to 'libavutil/avstring.c')
-rw-r--r--libavutil/avstring.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index b573dd6761..4cebbe04a6 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -91,6 +91,32 @@ size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...)
return len;
}
+char *av_asprintf(const char *fmt, ...)
+{
+ char *p = NULL;
+ va_list va;
+ int len;
+
+ va_start(va, fmt);
+ len = vsnprintf(NULL, 0, fmt, va);
+ va_end(va);
+ if (len < 0)
+ goto end;
+
+ p = av_malloc(len + 1);
+ if (!p)
+ goto end;
+
+ va_start(va, fmt);
+ len = vsnprintf(p, len + 1, fmt, va);
+ va_end(va);
+ if (len < 0)
+ av_freep(&p);
+
+end:
+ return p;
+}
+
char *av_d2str(double d)
{
char *str= av_malloc(16);