Home

avstrlcpy

av_strlcpy is a utility function found in FFmpeg’s libavutil library that provides a safe string-copy operation modeled after the BSD strlcpy function. It is used to copy a C string into a fixed-size destination buffer while minimizing the risk of buffer overflows.

The typical signature is: size_t av_strlcpy(char *dst, const char *src, size_t dst_size). The function copies up

Guidance and behavior: If dst_size is 0, av_strlcpy performs no writes but still returns the length of

Usage context: av_strlcpy is used throughout FFmpeg’s codebase to safely populate fixed-size buffers for messages, metadata,

See also: strlcpy, av_strlcat.

to
dst_size
-
1
characters
from
src
into
dst,
NUL-terminating
the
result
if
dst_size
is
non-zero.
It
returns
the
length
of
the
source
string
(the
number
of
characters
it
would
have
copied
in
a
space-unlimited
buffer).
If
the
return
value
is
greater
than
or
equal
to
dst_size,
truncation
occurred.
src.
This
makes
it
possible
to
determine
the
required
buffer
size
before
allocation.
The
function
does
not
attempt
to
handle
overlapping
memory
regions,
and
it
relies
on
valid
non-null
pointers
for
both
dst
and
src
in
typical
usage.
and
other
string
data,
reducing
common
errors
associated
with
manual
strncpy
or
snprintf-based
copying.
It
provides
consistent
semantics
across
platforms,
aiding
portability.