|
NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUE | ATTRIBUTES | STANDARDS | HISTORY | CAVEATS | BUGS | EXAMPLES | SEE ALSO | COLOPHON |
|
|
|
strncat(3) Library Functions Manual strncat(3)
strncat - append non-null bytes from a source array to a string,
and null-terminate the result
Standard C library (libc, -lc)
#include <string.h>
char *strncat(size_t ssize;
char *restrict dst, const char src[restrict ssize],
size_t ssize);
This function appends at most ssize non-null bytes from the array
pointed to by src, followed by a null character, to the end of the
string pointed to by dst. dst must point to a string contained in
a buffer that is large enough, that is, the buffer size must be at
least strlen(dst) + strnlen(src, ssize) + 1.
It is equivalent to
stpcpy(mempcpy(strnul(dst), src, strnlen(src, ssize)), ""), dst
strncat() returns dst.
For an explanation of the terms used in this section, see
attributes(7).
┌──────────────────────────────────────┬───────────────┬─────────┐
│ Interface │ Attribute │ Value │
├──────────────────────────────────────┼───────────────┼─────────┤
│ strncat() │ Thread safety │ MT-Safe │
└──────────────────────────────────────┴───────────────┴─────────┘
C11, POSIX.1-2008.
POSIX.1-2001, C89, SVr4, 4.3BSD.
The name of this function is confusing; it has no relation to
strncpy(3).
If the destination buffer does not already contain a string, or is
not large enough, the behavior is undefined. See _FORTIFY_SOURCE
in feature_test_macros(7).
This function can be very inefficient. Read about Shlemiel the
painter
⟨https://www.joelonsoftware.com/2001/12/11/back-to-basics/⟩.
#include <stdcountof.h>
#include <stdio.h>
#include <string.h>
#include <utmp.h>
void print_ut_user(struct utmp *ut);
void
print_ut_user(struct utmp *ut)
{
char buf[countof(ut->ut_user) + 1];
strcpy(buf, "");
strncat(buf, ut->ut_user, countof(ut->ut_user));
puts(buf);
}
string(3), string_copying(7)
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.18.tar.gz
fetched from
⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on
2026-05-24. 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.18 2026-02-25 strncat(3)
Pages that refer to this page: pmstrncat(3), pmstrncpy(3), string(3), wcsncat(3), feature_test_macros(7), signal-safety(7), string_copying(7)