diff options
author | Andrey Utkin <andrey.krieger.utkin@gmail.com> | 2014-07-03 14:37:08 +0300 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-07-07 21:28:18 +0200 |
commit | fcd1f6bc9d5caec25d925c5c4aa44cef15c37897 (patch) | |
tree | 3df698693aa6e4bb74c26731f98636044f7d8e7f /libavutil/bprint.c | |
parent | 06dae71d477ce0f48d9a8451c710ef13d62abf6c (diff) | |
download | ffmpeg-fcd1f6bc9d5caec25d925c5c4aa44cef15c37897.tar.gz |
avutil/bprint: Add av_bprint_fd_contents()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/bprint.c')
-rw-r--r-- | libavutil/bprint.c | 17 |
1 files changed, 17 insertions, 0 deletions
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 <stdio.h> #include <string.h> #include <time.h> +#include <unistd.h> #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 |