OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / release / man3 / strdup.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 Sun Jul 25 10:41:34 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified Wed Oct 17 01:12:26 2001 by John Levon <moz@compsoc.man.ac.uk>
29 .\"
30 .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi
31 .\"       all rights reserved.
32 .\" Translated Mon Jan 20 22:31:05 JST 1997
33 .\"       by YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
34 .\" Updated Fri Nov  2 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
35 .\"
36 .TH STRDUP 3  2011-10-01 "GNU" "Linux Programmer's Manual"
37 .SH 名前
38 strdup, strndup, strdupa, strndupa \- 文字列を複製する
39 .SH 書式
40 .nf
41 .B #include <string.h>
42 .sp
43 .BI "char *strdup(const char *" s );
44 .sp
45 .BI "char *strndup(const char *" s ", size_t " n );
46 .br
47 .BI "char *strdupa(const char *" s );
48 .br
49 .BI "char *strndupa(const char *" s ", size_t " n );
50 .fi
51 .sp
52 .in -4n
53 glibc 向けの機能検査マクロの要件
54 .RB ( feature_test_macros (7)
55 参照):
56 .in
57 .PD 0
58 .ad l
59 .sp
60 .BR strdup ():
61 .RS 4
62 _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
63 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
64 .br
65 || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
66 .RE
67 .PP
68 .BR strndup ():
69 .RS 4
70 .TP 4
71 glibc 2.10 以降:
72 POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700
73 .TP
74 glibc 2.10 より前:
75 _GNU_SOURCE
76 .RE
77 .PP
78 .BR strdupa (),
79 .BR strndupa ():
80 _GNU_SOURCE
81 .ad
82 .PD
83 .SH 説明
84 .BR strdup ()
85 関数は、文字列 \fIs\fPの複製である
86 新しい文字列へのポインタを返す。
87 新しい文字列のためのメモリは
88 .BR malloc (3)
89 で得ている。
90 そして、
91 .BR free (3)
92 で解放することができる。
93
94 .BR strndup ()
95 関数は同様であるが、最大で \fIn\fP 文字だけを複製する。
96 \fIs\fP が \fIn\fP よりも長い場合、\fIn\fP 文字だけが複製され、
97 終端の NULL バイト (\(aq\\0\(aq)) が追加される。
98
99 .BR strdupa ()
100
101 .BR strndupa ()
102 関数は同様であるが、
103 バッファを割り当てるのに \fBalloca(3)\fP を用いる。
104 これらの関数は GNU GCC を用いた場合にのみ有効で、
105 \fBalloca(3)\fP で記述されているのと同様の制限を受ける。
106 .SH 返り値
107 .BR strdup ()
108 関数は複製された文字列へのポインタ、または
109 十分なメモリが確保できなかった場合にはNULLを返す。
110 .SH エラー
111 .TP
112 .B ENOMEM
113 複製された文字列を割り当てる十分なメモリが確保できなかった。
114 .SH 準拠
115 .\" 4.3BSD-Reno, not (first) 4.3BSD.
116 .BR strdup ()
117 は SVr4, 4.3BSD, POSIX.1-2001 準拠である。
118 .BR strndup ()
119 は POSIX.1-2008 準拠である。
120 .BR strdupa (),
121 .BR strndupa ()
122 は GNU 拡張である。
123 .SH 関連項目
124 .BR alloca (3),
125 .BR calloc (3),
126 .BR free (3),
127 .BR malloc (3),
128 .BR realloc (3),
129 .BR string (3),
130 .BR wcsdup (3)