OSDN Git Service

(split) LDP: Update the version to 3.53 in 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 この関数は、 NULL 終端された文字列 \fIsrc\fP を文字列 \fIdest\fP に追加する。 具体例には、 \fIsize\fP が
98 \fIstrlen(dest)\fP より大きい場合には最大で \fIsize\-strlen(dest)\-1\fP バイトを \fIsrc\fP からコピーし、
99 結果の末尾に終端の NULL バイトを追加する。 この関数では \fBstrcat\fP() のバッファオーバーランが発生するという問題が修正されているが、
100 \fIsize\fP が小さすぎた場合にはデータが失われる問題には、 依然として呼び出し側で対処する必要がある。 この関数は \fBstrlcat\fP()
101 が作成しようとした文字列の長さを返す。 返り値が \fIsize\fP 以上の場合、 データロスが発生している。 データロスが問題となる場合は、
102 呼び出し側で、 呼び出し前に引き数をチェックするか、 この関数の返り値を検査するかのいずれかをしなければならない。 \fBstrlcat\fP() は
103 glibc には存在せず、 POSIX による標準化もされていないが、 Linux では \fIlibbsd\fP ライブラリ経由で利用できる。
104 .SH 関連項目
105 \fBbcopy\fP(3), \fBmemccpy\fP(3), \fBmemcpy\fP(3), \fBstrcpy\fP(3), \fBstring\fP(3),
106 \fBstrncpy\fP(3), \fBwcscat\fP(3), \fBwcsncat\fP(3)
107 .SH この文書について
108 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
109 である。プロジェクトの説明とバグ報告に関する情報は
110 http://www.kernel.org/doc/man\-pages/ に書かれている。