|
NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUE | STANDARDS | HISTORY | BUGS | SEE ALSO | COLOPHON |
|
|
|
strlcpy(3) Library Functions Manual strlcpy(3)
strlcpy, strlcat - string return-hypothetical-non-truncated-length
copy/catenate (with truncation)
Standard C library (libc, -lc)
#include <string.h>
size_t strlcpy(size_t dsize;
char dst[restrict dsize], const char *restrict src,
size_t dsize);
size_t strlcat(size_t dsize;
char dst[restrict dsize], const char *restrict src,
size_t dsize);
strlcpy() copies the string pointed to by src, into a string at
the buffer pointed to by dst.
strlcat() catenates the string pointed to by src, after the string
pointed to by dst (overwriting its terminating null byte).
For both functions, if the string doesn't fit in the buffer, it is
truncated.
These functions return the total length of the string they tried
to create, as if truncation didn't happen.
POSIX.1-2024.
OpenBSD 2.4, POSIX.1-2024, glibc 2.38.
These functions are vulnerable to denial of service (DoS) attacks,
since they read the entire source string.
strscpy(9) is a better function for copying with truncation, as it
doesn't have that issue. It's not provided by libc, so users
should write their own implementation.
strlcpy(3), strcpy(3), string(3)
This page is part of the man-pages (Linux kernel and C library
user-space interface documentation) project. Information about
the project can be found at
⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report
for this manual page, see
⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.
This page was obtained from the tarball man-pages-6.19.tar.gz
fetched from
⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on
2026-09-09. If you discover any rendering problems in this HTML
version of the page, or you believe there is a better or more up-
to-date source for the page, or you have corrections or
improvements to the information in this COLOPHON (which is not
part of the original manual page), send a mail to
man-pages@man7.org
Linux man-pages 6.19 2026-07-11 strlcpy(3)
Pages that refer to this page: strlcpy(3), string_copying(7)