OSDN Git Service

(split) LDP: Update drafts from PO files
[linuxjm/LDP_man-pages.git] / draft / 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 \fBstrcat\fP()  関数は、\fIdest\fP 文字列の後に \fIsrc\fP 文字列を付け加える。 その際に、\fIdest\fP の最後にある終端の
50 NULL バイト (\(aq\e0\(aq)  は上書きされ、新たに生成された文字列の末尾に終端の NULL バイトが付与される。 二つの文字列
51 \fIsrc\fP と \fIdest\fP は重なってはならない。 また、文字列 \fIdest\fP は、連結後の結果を格納するのに 十分な大きさでなければならない。
52 \fIdest\fP
53 が十分な大きさでない場合、プログラムがどのような動作をするか分からない。バッファオーバーランはセキュアなプログラムを攻撃する際に好んで使われる方法である。
54 .PP
55 \fBstrncat\fP()  も同様だが、以下の点が異なる。
56 .IP * 3
57 \fIsrc\fP のうち最大 \fIn\fP バイトが使用される。
58 .IP *
59 \fIsrc\fP が \fIn\fP バイト以上の場合、
60 \fIsrc\fP は NULL 終端されている必要はない。
61 .PP
62 \fBstrcat\fP()  と同じく、\fIdest\fP に格納される結果の文字列は常に NULL 終端される。
63 .PP
64 \fIsrc\fP が \fIn\fP バイト以上の場合、 \fBstrncat\fP() は \fIdest\fP に \fIn+1\fP
65 バイトを書き込む (\fIsrc\fP からの \fIn\fP バイトと終端の NULL バイトである)。
66 したがって、\fIdest\fP の大きさは最低でも \fIstrlen(dest)+n+1\fP でなければ
67 ならない。
68
69 \fBstrncat\fP()  の簡単な実装は以下のような感じであろう:
70 .in +4n
71 .nf
72
73 char*
74 strncat(char *dest, const char *src, size_t n)
75 {
76     size_t dest_len = strlen(dest);
77     size_t i;
78
79     for (i = 0 ; i < n && src[i] != \(aq\e0\(aq ; i++)
80         dest[dest_len + i] = src[i];
81     dest[dest_len + i] = \(aq\e0\(aq;
82
83     return dest;
84 }
85 .fi
86 .in
87 .SH 返り値
88 \fBstrcat\fP()  関数と \fBstrncat\fP()  関数は、結果としてできる文字列 \fIdest\fP へのポインタを返す。
89 .SH 準拠
90 SVr4, 4.3BSD, C89, C99.
91 .SH 注意
92 いくつかのシステム (BSD、Solaris など) では以下の関数が提供されている。
93
94     size_t strlcat(char *dest, const char *src, size_t size);
95
96 .\" https://lwn.net/Articles/506530/
97 This function appends the null\-terminated string \fIsrc\fP to the string
98 \fIdest\fP, copying at most \fIsize\-strlen(dest)\-1\fP from \fIsrc\fP, and adds a null
99 terminator to the result, \fIunless\fP \fIsize\fP is less than \fIstrlen(dest)\fP.
100 This function fixes the buffer overrun problem of \fBstrcat\fP(), but the
101 caller must still handle the possibility of data loss if \fIsize\fP is too
102 small.  The function returns the length of the string \fBstrlcat\fP()  tried to
103 create; if the return value is greater than or equal to \fIsize\fP, data loss
104 occurred.  If data loss matters, the caller \fImust\fP either check the
105 arguments before the call, or test the function return value.  \fBstrlcat\fP()
106 is not present in glibc and is not standardized by POSIX, but is available
107 on Linux via the \fIlibbsd\fP library.
108 .SH 関連項目
109 \fBbcopy\fP(3), \fBmemccpy\fP(3), \fBmemcpy\fP(3), \fBstrcpy\fP(3), \fBstring\fP(3),
110 \fBstrncpy\fP(3), \fBwcscat\fP(3), \fBwcsncat\fP(3)
111 .SH この文書について
112 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.51 の一部
113 である。プロジェクトの説明とバグ報告に関する情報は
114 http://www.kernel.org/doc/man\-pages/ に書かれている。