[FFmpeg-cvslog] av_string: add av_asprintf().

Clément Bœsch git at videolan.org
Sun Sep 4 09:38:26 CEST 2011


ffmpeg | branch: master | Clément Bœsch <ubitux at gmail.com> | Sat Sep  3 19:51:28 2011 +0200| [61e2e2969127e4cb8e0d32151fed3e03515fe436] | committer: Clément Bœsch

av_string: add av_asprintf().

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=61e2e2969127e4cb8e0d32151fed3e03515fe436
---

 doc/APIchanges       |    3 +++
 libavutil/avstring.c |   26 ++++++++++++++++++++++++++
 libavutil/avstring.h |   10 ++++++++++
 libavutil/avutil.h   |    2 +-
 4 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 75c4d6f..bd06114 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:   2011-04-18
 
 API changes, most recent first:
 
+2011-09-xx - xxxxxxx - lavu 51.16.0
+  Add av_asprintf().
+
 2011-08-22 - dacd827 - lavf 53.10.0
   Add av_find_program_from_stream().
 
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index b573dd6..4cebbe0 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);
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 662af6b..2be84a9 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -111,6 +111,16 @@ size_t av_strlcat(char *dst, const char *src, size_t size);
 size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4);
 
 /**
+ * Print arguments following specified format into a large enough auto
+ * allocated buffer. It is similar to GNU asprintf().
+ * @param fmt printf-compatible format string, specifying how the
+ *            following parameters are used.
+ * @return the allocated string
+ * @note You have to free the string yourself with av_free().
+ */
+char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2);
+
+/**
  * Convert a number to a av_malloced string.
  */
 char *av_d2str(double d);
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index f77cde7..06c0470 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -40,7 +40,7 @@
 #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
 
 #define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 15
+#define LIBAVUTIL_VERSION_MINOR 16
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list