OSDN Git Service

Update release for LDP 3.67
[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 .\"
38 .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi
39 .\"       all rights reserved.
40 .\" Translated Mon Jan 20 22:47:14 JST 1997
41 .\"       by YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
42 .\" Updated & Modified Fri Feb 18 00:30:00 JST 2005
43 .\"       by Yuichi SATO <ysato444@yahoo.co.jp>
44 .\" Updated 2007-07-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.58
45 .\" Updated 2012-05-29, Akihiro MOTOKI <amotoki@gmail.com>
46 .\" Updated 2013-05-06, Akihiro MOTOKI <amotoki@gmail.com>
47 .\"
48 .TH STRCAT 3 2014\-01\-20 GNU "Linux Programmer's Manual"
49 .SH 名前
50 strcat, strncat \- 二つの文字列を連結する
51 .SH 書式
52 .nf
53 \fB#include <string.h>\fP
54 .sp
55 \fBchar *strcat(char *\fP\fIdest\fP\fB, const char *\fP\fIsrc\fP\fB);\fP
56 .sp
57 \fBchar *strncat(char *\fP\fIdest\fP\fB, const char *\fP\fIsrc\fP\fB, size_t \fP\fIn\fP\fB);\fP
58 .fi
59 .SH 説明
60 \fBstrcat\fP()  関数は、\fIdest\fP 文字列の後に \fIsrc\fP 文字列を付け加える。 その際に、\fIdest\fP
61 の最後にある終端のヌルバイト (\(aq\e0\(aq)  は上書きされ、新たに生成された文字列の末尾に終端のヌルバイトが付与される。 二つの文字列
62 \fIsrc\fP と \fIdest\fP は重なってはならない。 また、文字列 \fIdest\fP は、連結後の結果を格納するのに 十分な大きさでなければならない。
63 \fIdest\fP が十分な大きさでない場合、プログラムがどのような動作をするか分からない。
64 バッファオーバーランはセキュアなプログラムを攻撃する際に好んで使われる方法である。
65 .PP
66 \fBstrncat\fP()  も同様だが、以下の点が異なる。
67 .IP * 3
68 \fIsrc\fP のうち最大 \fIn\fP バイトが使用される。
69 .IP *
70 \fIsrc\fP が \fIn\fP バイト以上の場合、
71 \fIsrc\fP はヌル終端されている必要はない。
72 .PP
73 \fBstrcat\fP()  と同じく、\fIdest\fP に格納される結果の文字列は常にヌル終端される。
74 .PP
75 \fIsrc\fP が \fIn\fP バイト以上の場合、 \fBstrncat\fP() は \fIdest\fP に \fIn+1\fP
76 バイトを書き込む (\fIsrc\fP からの \fIn\fP バイトと終端のヌルバイトである)。
77 したがって、\fIdest\fP の大きさは最低でも \fIstrlen(dest)+n+1\fP でなければ
78 ならない。
79
80 \fBstrncat\fP()  の簡単な実装は以下のような感じであろう:
81 .in +4n
82 .nf
83
84 char*
85 strncat(char *dest, const char *src, size_t n)
86 {
87     size_t dest_len = strlen(dest);
88     size_t i;
89
90     for (i = 0 ; i < n && src[i] != \(aq\e0\(aq ; i++)
91         dest[dest_len + i] = src[i];
92     dest[dest_len + i] = \(aq\e0\(aq;
93
94     return dest;
95 }
96 .fi
97 .in
98 .SH 返り値
99 \fBstrcat\fP()  関数と \fBstrncat\fP()  関数は、結果としてできる文字列 \fIdest\fP へのポインタを返す。
100 .SH 属性
101 .SS "マルチスレッディング (pthreads(7) 参照)"
102 関数 \fBstrcat\fP() と \fBstrncat\fP() はスレッドセーフである。
103 .SH 準拠
104 SVr4, 4.3BSD, C89, C99.
105 .SH 注意
106 いくつかのシステム (BSD、Solaris など) では以下の関数が提供されている。
107
108     size_t strlcat(char *dest, const char *src, size_t size);
109
110 .\" https://lwn.net/Articles/506530/
111 この関数は、ヌル終端された文字列 \fIsrc\fP を文字列 \fIdest\fP に追加する。 具体例には、 \fIsize\fP が \fIstrlen(dest)\fP
112 より大きい場合には最大で \fIsize\-strlen(dest)\-1\fP バイトを \fIsrc\fP からコピーし、 結果の末尾に終端のヌルバイトを追加する。
113 この関数では \fBstrcat\fP() のバッファオーバーランが発生するという問題が修正されているが、  \fIsize\fP
114 が小さすぎた場合にはデータが失われる問題には、 依然として呼び出し側で対処する必要がある。 この関数は \fBstrlcat\fP()
115 が作成しようとした文字列の長さを返す。 返り値が \fIsize\fP 以上の場合、 データロスが発生している。 データロスが問題となる場合は、
116 呼び出し側で、 呼び出し前に引き数をチェックするか、 この関数の返り値を検査するかのいずれかをしなければならない。 \fBstrlcat\fP() は
117 glibc には存在せず、 POSIX による標準化もされていないが、 Linux では \fIlibbsd\fP ライブラリ経由で利用できる。
118 .SH 関連項目
119 \fBbcopy\fP(3), \fBmemccpy\fP(3), \fBmemcpy\fP(3), \fBstrcpy\fP(3), \fBstring\fP(3),
120 \fBstrncpy\fP(3), \fBwcscat\fP(3), \fBwcsncat\fP(3)
121 .SH この文書について
122 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
123 である。プロジェクトの説明とバグ報告に関する情報は
124 http://www.kernel.org/doc/man\-pages/ に書かれている。