OSDN Git Service

7877ce5bfad1836acad24d8528c95055fe7d82c4
[linuxjm/LDP_man-pages.git] / release / man3 / strcat.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\" Modified Sat Jul 24 18:11:47 1993 by Rik Faith (faith@cs.unc.edu)
30 .\" 2007-06-15, Marc Boyer <marc.boyer@enseeiht.fr> + mtk
31 .\"     Improve discussion of strncat().
32 .\"*******************************************************************
33 .\"
34 .\" This file was generated with po4a. Translate the source file.
35 .\"
36 .\"*******************************************************************
37 .TH STRCAT 3 2012\-07\-19 GNU "Linux Programmer's Manual"
38 .SH 名前
39 strcat, strncat \- 二つの文字列を連結する
40 .SH 書式
41 .nf
42 \fB#include <string.h>\fP
43 .sp
44 \fBchar *strcat(char *\fP\fIdest\fP\fB, const char *\fP\fIsrc\fP\fB);\fP
45 .sp
46 \fBchar *strncat(char *\fP\fIdest\fP\fB, const char *\fP\fIsrc\fP\fB, size_t \fP\fIn\fP\fB);\fP
47 .fi
48 .SH 説明
49 The \fBstrcat\fP()  function appends the \fIsrc\fP string to the \fIdest\fP string,
50 overwriting the terminating null byte (\(aq\e0\(aq) at the end of \fIdest\fP,
51 and then adds a terminating null byte.  The strings may not overlap, and the
52 \fIdest\fP string must have enough space for the result.  If \fIdest\fP is not
53 large enough, program behavior is unpredictable; \fIbuffer overruns are a
54 favorite avenue for attacking secure programs\fP.
55 .PP
56 \fBstrncat\fP()  も同様だが、以下の点が異なる。
57 .IP * 3
58 \fIsrc\fP のうち最大 \fIn\fP バイトが使用される。
59 .IP *
60 \fIsrc\fP が \fIn\fP バイト以上の場合、
61 \fIsrc\fP は NULL 終端されている必要はない。
62 .PP
63 \fBstrcat\fP()  と同じく、\fIdest\fP に格納される結果の文字列は常に NULL 終端される。
64 .PP
65 \fIsrc\fP が \fIn\fP バイト以上の場合、 \fBstrncat\fP() は \fIdest\fP に \fIn+1\fP
66 バイトを書き込む (\fIsrc\fP からの \fIn\fP バイトと終端の NULL バイトである)。
67 したがって、\fIdest\fP の大きさは最低でも \fIstrlen(dest)+n+1\fP でなければ
68 ならない。
69
70 \fBstrncat\fP()  の簡単な実装は以下のような感じであろう:
71 .in +4n
72 .nf
73
74 char*
75 strncat(char *dest, const char *src, size_t n)
76 {
77     size_t dest_len = strlen(dest);
78     size_t i;
79
80     for (i = 0 ; i < n && src[i] != \(aq\e0\(aq ; i++)
81         dest[dest_len + i] = src[i];
82     dest[dest_len + i] = \(aq\e0\(aq;
83
84     return dest;
85 }
86 .fi
87 .in
88 .SH 返り値
89 \fBstrcat\fP()  関数と \fBstrncat\fP()  関数は、結果としてできる文字列 \fIdest\fP へのポインタを返す。
90 .SH 準拠
91 SVr4, 4.3BSD, C89, C99.
92 .SH 注意
93 Some systems (the BSDs, Solaris, and others) provide the following function:
94
95     size_t strlcat(char *dest, const char *src, size_t size);
96
97 .\" https://lwn.net/Articles/506530/
98 This function appends the null\-terminated string \fIsrc\fP to the string
99 \fIdest\fP, copying at most \fIsize\-strlen(dest)\-1\fP from \fIsrc\fP, and adds a null
100 terminator to the result, \fIunless\fP \fIsize\fP is less than \fIstrlen(dest)\fP.
101 This function fixes the buffer overrun problem of \fBstrcat\fP(), but the
102 caller must still handle the possibility of data loss if \fIsize\fP is too
103 small.  The function returns the length of the string \fBstrlcat\fP()  tried to
104 create; if the return value is greater than or equal to \fIsize\fP, data loss
105 occurred.  If data loss matters, the caller \fImust\fP either check the
106 arguments before the call, or test the function return value.  \fBstrlcat\fP()
107 is not present in glibc and is not standardized by POSIX, but is available
108 on Linux via the \fIlibbsd\fP library.
109 .SH 関連項目
110 \fBbcopy\fP(3), \fBmemccpy\fP(3), \fBmemcpy\fP(3), \fBstrcpy\fP(3), \fBstring\fP(3),
111 \fBstrncpy\fP(3), \fBwcscat\fP(3), \fBwcsncat\fP(3)
112 .SH この文書について
113 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.51 の一部
114 である。プロジェクトの説明とバグ報告に関する情報は
115 http://www.kernel.org/doc/man\-pages/ に書かれている。