]> git.sesse.net Git - ffmpeg/commitdiff
lavf/aviobuf: add ff_get_chomp_line
authorJun Zhao <mypopydev@gmail.com>
Mon, 9 Apr 2018 15:05:42 +0000 (23:05 +0800)
committerJun Zhao <jun.zhao@intel.com>
Thu, 12 Apr 2018 08:04:58 +0000 (16:04 +0800)
Same as ff_get_line but strip the white-space characters in the
string tail.

Signed-off-by: Jun Zhao <mypopydev@gmail.com>
libavformat/aviobuf.c
libavformat/internal.h

index 95b33644784c04de3b8d07f0e3504d88ce35bc40..e752d0e1a659bb167afcbc77c78ea3dc0884efcb 100644 (file)
@@ -823,6 +823,14 @@ int ff_get_line(AVIOContext *s, char *buf, int maxlen)
     return i;
 }
 
+int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen)
+{
+    int len = ff_get_line(s, buf, maxlen);
+    while (len > 0 && av_isspace(buf[len - 1]))
+        buf[--len] = '\0';
+    return len;
+}
+
 int64_t ff_read_line_to_bprint(AVIOContext *s, AVBPrint *bp)
 {
     int len, end;
index c50382ad29f64c7729845a2ba38f665320711bd0..35826829250231c7f61010929c297a4d29f58589 100644 (file)
@@ -299,6 +299,16 @@ void ff_put_v(AVIOContext *bc, uint64_t val);
  */
 int ff_get_line(AVIOContext *s, char *buf, int maxlen);
 
+/**
+ * Same as ff_get_line but strip the white-space characters in the text tail
+ *
+ * @param s the read-only AVIOContext
+ * @param buf buffer to store the read line
+ * @param maxlen size of the buffer
+ * @return the length of the string written in the buffer
+ */
+int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen);
+
 /**
  * Read a whole line of text from AVIOContext to an AVBPrint buffer. Stop
  * reading after reaching a \\r, a \\n, a \\r\\n, a \\0 or EOF.  The line