[FFmpeg-devel] [PATCH 1/5] bprint: add av_bprint_init_for_buffer().

Stefano Sabatini stefasab at gmail.com
Tue Jun 5 12:07:59 CEST 2012


On date Sunday 2012-06-03 21:44:46 +0200, Nicolas George encoded:
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  libavutil/bprint.c |   14 ++++++++++++++
>  libavutil/bprint.h |    7 +++++++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/libavutil/bprint.c b/libavutil/bprint.c
> index 115bf0c..646f0aa 100644
> --- a/libavutil/bprint.c
> +++ b/libavutil/bprint.c
> @@ -78,6 +78,15 @@ void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
>          av_bprint_alloc(buf, size_init - 1);
>  }
>  
> +void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size)
> +{
> +    buf->str      = buffer;
> +    buf->len      = 0;
> +    buf->size     = size;
> +    buf->size_max = size;
> +    *buf->str = 0;
> +}
> +
>  void av_bprintf(AVBPrint *buf, const char *fmt, ...)
>  {
>      unsigned room;
> @@ -178,6 +187,7 @@ static void bprint_pascal(AVBPrint *b, unsigned size)
>  int main(void)
>  {
>      AVBPrint b;
> +    char buf[256];
>  
>      av_bprint_init(&b, 0, -1);
>      bprint_pascal(&b, 5);
> @@ -208,6 +218,10 @@ int main(void)
>      bprint_pascal(&b, 25);
>      printf("Long text count only buffer: %zu/%u\n", strlen(b.str), b.len);
>  
> +    av_bprint_init_for_buffer(&b, buf, sizeof(buf));
> +    bprint_pascal(&b, 25);
> +    printf("Long text count only buffer: %zu/%u\n", strlen(buf), b.len);
> +
>      return 0;
>  }
>  
> diff --git a/libavutil/bprint.h b/libavutil/bprint.h
> index ad65afe..3f93b1f 100644
> --- a/libavutil/bprint.h
> +++ b/libavutil/bprint.h
> @@ -100,6 +100,13 @@ void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max);
>  #define AV_BPRINT_SIZE_COUNT_ONLY 0
>  
>  /**
> + * Init a print buffer for a pre-existing buffer.

I find the "for a pre-existing buffer" expression confusing, indeed I
couldn't tell what it means without peeking at the code.
Maybe more clear:
using a pre-existing buffer

Also tell that "size" specifies the passed buffer size in bytes.

> + *
> + * The buffer will not be reallocated.
> + */
> +void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size);

Same for name, maybe for_buffer -> use_buffer, but I'm not strong on
this.

[...]

Looks good otherwise.
-- 
FFmpeg = Fiendish and Frenzy Mind-dumbing Pacific Enhanced Geisha


More information about the ffmpeg-devel mailing list