On Tue, 12 Aug 2014 21:34:33 +0200, wm4 <nfx...@googlemail.com> wrote: > On Tue, 12 Aug 2014 16:54:50 +0000 > Anton Khirnov <an...@khirnov.net> wrote: > > > --- > > doc/APIchanges | 3 +++ > > libavutil/mem.c | 20 ++++++++++++++++++++ > > libavutil/mem.h | 10 ++++++++++ > > libavutil/version.h | 2 +- > > 4 files changed, 34 insertions(+), 1 deletion(-) > > > > diff --git a/doc/APIchanges b/doc/APIchanges > > index 6e5242e..fc56677 100644 > > --- a/doc/APIchanges > > +++ b/doc/APIchanges > > @@ -13,6 +13,9 @@ libavutil: 2014-08-09 > > > > API changes, most recent first: > > > > +2014-08-xx - xxxxxxx - lavu 54.2.0 - mem.h > > + Add av_strndup(). > > + > > 2014-04-xx - xxxxxxx - lavr 2.1.0 - avresample.h > > Add avresample_convert_frame() and avresample_config(). > > > > diff --git a/libavutil/mem.c b/libavutil/mem.c > > index be42342..129aff1 100644 > > --- a/libavutil/mem.c > > +++ b/libavutil/mem.c > > @@ -222,6 +222,26 @@ char *av_strdup(const char *s) > > return ptr; > > } > > > > +char *av_strndup(const char *s, size_t len) > > +{ > > + size_t len1; > > + char *ret = NULL; > > + > > + if (!s) > > + return NULL; > > + > > + len1 = strlen(s); > > + len = FFMIN(len, len1); > > + > > + ret = av_realloc(NULL, len + 1); > > I'm guessing using av_realloc instead of av_malloc avoids wasting space > by not aligning the allocation? >
Mainly it makes the string reallocable. It's also what av_strdup does. -- Anton Khirnov _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel