strncat(3)

strncat3

Nonstring catenate

Usage

#include <string.h>  // see memory.h(3head)

char *strncat(size_t ssize; char *restrict dst, const char src[restrict ssize], size_t ssize);

Library

Standard C library (libc, -lc)

Overview

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

Return value

strncat() returns dst.

Attributes

For an explanation of the terms used in this section, see attributes(7).

InterfaceAttributeValue
strncat()Thread safetyMT-Safe

Caveats

The name of this function is confusing:

•

It has no relation to strncpy(3).

•

It doesn't truncate the input nonstring.

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).

Examples

#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);
}

Releases

19 releases since Debian 1.1 (Buzz); the text changed 13 times.

  1. 1.1–2.2
  2. 3.0
  3. 3.1
  4. 4.0
  5. 5.0
  6. 6.0
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. Arch

Standards

C11, POSIX.1-2008.

History

POSIX.1-2001, C89, SVr4, 4.3BSD.

From man-pages 6.19-1 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.