diff options
author | Marton Balint <cus@passwd.hu> | 2018-02-03 22:03:58 +0100 |
---|---|---|
committer | Marton Balint <cus@passwd.hu> | 2018-02-24 20:17:04 +0100 |
commit | dcb2ef2211fd472b4fa235e9f1c4a48582e44049 (patch) | |
tree | 7d8e7d18b38431d9bdbb887d58c3b701f85c02a3 /libavformat/aviobuf.c | |
parent | 5f36c546ec4ef279027da6e0f0ef1276bea4207a (diff) |
avformat/aviobuf: add ff_read_line_to_bprint and ff_read_line_to_bprint_overwrite functions
To be able to read lines longer than a static buffer size.
Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavformat/aviobuf.c')
-rw-r--r-- | libavformat/aviobuf.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index d63db3897f..95b3364478 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -823,6 +823,52 @@ int ff_get_line(AVIOContext *s, char *buf, int maxlen) return i; } +int64_t ff_read_line_to_bprint(AVIOContext *s, AVBPrint *bp) +{ + int len, end; + int64_t read = 0; + char tmp[1024]; + char c; + + do { + len = 0; + do { + c = avio_r8(s); + end = (c == '\r' || c == '\n' || c == '\0'); + if (!end) + tmp[len++] = c; + } while (!end && len < sizeof(tmp)); + av_bprint_append_data(bp, tmp, len); + read += len; + } while (!end); + + if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s)) + avio_skip(s, -1); + + if (!c && s->error) + return s->error; + + if (!c && !read && avio_feof(s)) + return AVERROR_EOF; + + return read; +} + +int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp) +{ + int64_t ret; + + av_bprint_clear(bp); + ret = ff_read_line_to_bprint(s, bp); + if (ret < 0) + return ret; + + if (!av_bprint_is_complete(bp)) + return AVERROR(ENOMEM); + + return bp->len; +} + int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen) { int i; |