From fcd1f6bc9d5caec25d925c5c4aa44cef15c37897 Mon Sep 17 00:00:00 2001 From: Andrey Utkin Date: Thu, 3 Jul 2014 14:37:08 +0300 Subject: avutil/bprint: Add av_bprint_fd_contents() Signed-off-by: Michael Niedermayer --- libavutil/bprint.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'libavutil/bprint.c') diff --git a/libavutil/bprint.c b/libavutil/bprint.c index 0a0d07861b..becb4d8013 100644 --- a/libavutil/bprint.c +++ b/libavutil/bprint.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "avassert.h" #include "avstring.h" #include "bprint.h" @@ -304,6 +305,22 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_cha } } +int av_bprint_fd_contents(AVBPrint *pb, int fd) +{ + int ret; + char buf[1024]; + while (1) { + ret = read(fd, buf, sizeof(buf)); + if (!ret) + return 0; + else if (ret < 0) + return AVERROR(errno); + av_bprint_append_data(pb, buf, ret); + if (!av_bprint_is_complete(pb)) + return AVERROR(ENOMEM); + } +} + #ifdef TEST #undef printf -- cgit v1.2.3