]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/strcat.3
s/\\'/\\(aq/
[thirdparty/man-pages.git] / man3 / strcat.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\" 386BSD man pages
27 .\" Modified Sat Jul 24 18:11:47 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" 2007-06-15, Marc Boyer <marc.boyer@enseeiht.fr> + mtk
29 .\" Improve discussion of strncat().
30 .TH STRCAT 3 2007-06-15 "GNU" "Linux Programmer's Manual"
31 .SH NAME
32 strcat, strncat \- concatenate two strings
33 .SH SYNOPSIS
34 .nf
35 .B #include <string.h>
36 .sp
37 .BI "char *strcat(char *" dest ", const char *" src );
38 .sp
39 .BI "char *strncat(char *" dest ", const char *" src ", size_t " n );
40 .fi
41 .SH DESCRIPTION
42 The
43 .BR strcat ()
44 function appends the \fIsrc\fP string to the
45 \fIdest\fP string, overwriting the null byte (\(aq\\0\(aq) at the end of
46 \fIdest\fP, and then adds a terminating null byte.
47 The strings may not overlap, and the \fIdest\fP string must have
48 enough space for the result.
49 .PP
50 The
51 .BR strncat ()
52 function is similar, except that
53 .IP * 3
54 it will use at most \fIn\fP characters from \fIsrc\fP; and
55 .IP *
56 \fIsrc\fP does not need to be null terminated if it contains
57 \fIn\fP or more characters.
58 .PP
59 As with
60 .BR strcat (),
61 the resulting string in \fIdest\fP is always null terminated.
62 .PP
63 If \fIsrc\fP contains \fIn\fP or more characters,
64 .BR strcat ()
65 writes \fIn+1\fP characters to \fIdest\fP (\fIn\fP
66 from \fIsrc\fP plus the terminating null byte).
67 Therefore, the size of \fIdest\fP must be at least
68 \fIstrlen(dest)+n+1\fP.
69
70 A simple implementation of
71 .BR strncat ()
72 might be:
73 .in +4n
74 .nf
75
76 char*
77 strncat(char *dest, const char *src, size_t n)
78 {
79 size_t dest_len = strlen(dest);
80 size_t i;
81
82 for (i = 0 ; i < n && src[i] != \(aq\\0\(aq ; i++)
83 dest[dest_len + i] = src[i];
84 dest[dest_len + i] = \(aq\\0\(aq;
85
86 return dest;
87 }
88 .fi
89 .in
90 .SH "RETURN VALUE"
91 The
92 .BR strcat ()
93 and
94 .BR strncat ()
95 functions return a pointer to the resulting string \fIdest\fP.
96 .SH "CONFORMING TO"
97 SVr4, 4.3BSD, C89, C99.
98 .SH "SEE ALSO"
99 .BR bcopy (3),
100 .BR memccpy (3),
101 .BR memcpy (3),
102 .BR strcpy (3),
103 .BR strncpy (3),
104 .BR wcscat (3),
105 .BR wcsncat (3)