Debian Codegraph @

upstream/debian-unstable/man3/strncat.3

raw
1 '\" t
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH strncat 3 2026-02-25 "Linux man-pages 6.18"
7 .SH NAME
8 strncat
9 \-
10 append non-null bytes from a source array to a string,
11 and null-terminate the result
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ,\~ \-lc )
15 .SH SYNOPSIS
16 .nf
17 .B #include <string.h>
18 .P
19 .BR "char *strncat(" "size_t ssize;"
20 .BI " char *restrict " dst ", const char " src "[restrict " ssize ],
21 .BI " size_t " ssize );
22 .fi
23 .SH DESCRIPTION
24 This function appends at most
25 .I ssize
26 non-null bytes from the array pointed to by
27 .IR src ,
28 followed by a null character,
29 to the end of the string pointed to by
30 .IR dst .
31 .I dst
32 must point to a string contained in a buffer that is large enough,
33 that is, the buffer size must be at least
34 .IR "strlen(dst) + strnlen(src, ssize) + 1" .
35 .P
36 It is equivalent to
37 .P
38 .in +4n
39 .EX
40 stpcpy(mempcpy(strnul(dst), src, strnlen(src, ssize)), ""), dst
41 .EE
42 .in
43 .SH RETURN VALUE
44 .BR strncat ()
45 returns
46 .IR dst .
47 .SH ATTRIBUTES
48 For an explanation of the terms used in this section, see
49 .BR attributes (7).
50 .TS
51 allbox;
52 lbx lb lb
53 l l l.
54 Interface Attribute Value
55 T{
56 .na
57 .nh
58 .BR strncat ()
59 T} Thread safety MT-Safe
60 .TE
61 .SH STANDARDS
62 C11, POSIX.1-2008.
63 .SH HISTORY
64 POSIX.1-2001, C89, SVr4, 4.3BSD.
65 .SH CAVEATS
66 The name of this function is confusing;
67 it has no relation to
68 .BR strncpy (3).
69 .P
70 If the destination buffer does not already contain a string,
71 or is not large enough,
72 the behavior is undefined.
73 See
74 .B _FORTIFY_SOURCE
75 in
76 .BR feature_test_macros (7).
77 .SH BUGS
78 This function can be very inefficient.
79 Read about
80 .UR https:\://www.joelonsoftware.com/\:2001/12/11/\:back\-to\-basics/
81 Shlemiel the painter
82 .UE .
83 .SH EXAMPLES
84 .\" SRC BEGIN (strncat.c)
85 .EX
86 #include <stdcountof.h>
87 #include <stdio.h>
88 #include <string.h>
89 #include <utmp.h>
90 \&
91 void print_ut_user(struct utmp *ut);
92 \&
93 void
94 print_ut_user(struct utmp *ut)
95 {
96 char buf[countof(ut\->ut_user) + 1];
97 \&
98 strcpy(buf, "");
99 strncat(buf, ut\->ut_user, countof(ut\->ut_user));
100 puts(buf);
101 }
102 .EE
103 .\" SRC END
104 .in
105 .SH SEE ALSO
106 .BR string (3),
107 .BR string_copying (7)