[FFmpeg-cvslog] avio: add avio_get_str()

Reimar Döffinger git
Sat Mar 5 03:28:22 CET 2011


ffmpeg | branch: master | Reimar D?ffinger <Reimar.Doeffinger at gmx.de> | Thu Mar  3 13:51:55 2011 +0100| [3e1a8e1ec1897086f063667480ec1a0eafd03392] | committer: Michael Niedermayer

avio: add avio_get_str()

Signed-off-by: Ronald S. Bultje <rsbultje at gmail.com>
(cherry picked from commit 41d8555f72e3bc60cf93af2a1a4786b452fd2736)

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

 libavformat/avio.h    |   14 ++++++++++++++
 libavformat/aviobuf.c |   17 +++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/libavformat/avio.h b/libavformat/avio.h
index cc46ad7..fd4839c 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -526,6 +526,20 @@ unsigned int avio_rl32(AVIOContext *s);
 uint64_t     avio_rl64(AVIOContext *s);
 
 /**
+ * Read a string from pb into buf. The reading will terminate when either
+ * a NULL character was encountered, maxlen bytes have been read, or nothing
+ * more can be read from pb. The result is guaranteed to be NULL-terminated, it
+ * will be truncated if buf is too small.
+ * Note that the string is not interpreted or validated in any way, it
+ * might get truncated in the middle of a sequence for multi-byte encodings.
+ *
+ * @return number of bytes read (is always <= maxlen).
+ * If reading ends on EOF or error, the return value will be one more than
+ * bytes actually read.
+ */
+int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
+
+/**
  * Read a UTF-16 string from pb and convert it to UTF-8.
  * The reading will terminate when either a null or invalid character was
  * encountered or maxlen bytes have been read.
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 3f3721c..5b2f9c0 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -705,6 +705,23 @@ int ff_get_line(AVIOContext *s, char *buf, int maxlen)
     return i;
 }
 
+int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
+{
+    int i;
+
+    // reserve 1 byte for terminating 0
+    buflen = FFMIN(buflen - 1, maxlen);
+    for (i = 0; i < buflen; i++)
+        if (!(buf[i] = avio_r8(s)))
+            return i + 1;
+    if (buflen)
+        buf[i] = 0;
+    for (; i < maxlen; i++)
+        if (!avio_r8(s))
+            return i + 1;
+    return maxlen;
+}
+
 #define GET_STR16(type, read) \
     int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
 {\




More information about the ffmpeg-cvslog mailing list