| strncat(3P, 3p) | concatenate a string with part of another |
| strncat(3) | append non-null bytes from a source array to a string, and null-terminate the result |
| stpecpy, stpecpyx, string_copying, ustpcpy, ustr2stp, zustr2stp, zustr2ustp, stpcpy, stpncpy, strcat, strcpy, strlcat, strlcpy, strncat, strncpy, strtcpy(3, 7) | copying strings and character sequences |
| string, stpcpy, index, rindex, strcasecmp, strcat, strchr, strcmp, strcoll, strcpy, strcspn, strdup, strfry, strlen, strncasecmp, strncat, strncmp, strncpy, strpbrk, strrchr, strsep, strspn, strstr, strtok, strxfrm(3) | string operations |
| 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.
An implementation of this function might be:
char *
strncat(char *restrict dst, const char *restrict src, size_t ssize)
{
#define strnul(s) (s + strlen(s))
stpcpy(mempcpy(strnul(dst), src, strnlen(src, ssize)), "");
return 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.
#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)
| 2026-02-10 | Linux man-pages 6.17 |