[FFmpeg-devel] [PATCH] lavf/aviobuf: add ff_get_line2() variant

Michael Niedermayer michael at niedermayer.cc
Thu Oct 13 22:59:19 EEST 2016


On Thu, Oct 13, 2016 at 07:40:59PM +0200, Stefano Sabatini wrote:
> This allows to probe if the read line was partially discarded.
> ---
>  libavformat/aviobuf.c  | 10 +++++++++-
>  libavformat/internal.h | 14 ++++++++++++++
>  2 files changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index 134d627..28183b4 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -764,18 +764,26 @@ unsigned int avio_rb32(AVIOContext *s)
>  
>  int ff_get_line(AVIOContext *s, char *buf, int maxlen)
>  {
> -    int i = 0;
> +    return ff_get_line2(s, buf, maxlen, NULL);
> +}
> +
> +int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen)
> +{
> +    int i = 0, j = 0;
>      char c;
>  
>      do {
>          c = avio_r8(s);
>          if (c && i < maxlen-1)
>              buf[i++] = c;
> +        j++;
>      } while (c != '\n' && c != '\r' && c);

"\n" and "\0" would i belive both have a j=1 but they would have
differig i
is that intended ? (seems to me that this would make truncation
detection more annoying)
or am i missing something that avoids this difference?

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The educated differ from the uneducated as much as the living from the
dead. -- Aristotle 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161013/cdc093dc/attachment.sig>


More information about the ffmpeg-devel mailing list