OSDN Git Service

(split) LDP man-pages の original/ を v3.29 に更新。
[linuxjm/LDP_man-pages.git] / original / 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 .TH STRDUP 3  2010-09-26 "GNU" "Linux Programmer's Manual"
30 .SH NAME
31 strdup, strndup, strdupa, strndupa \- duplicate a string
32 .SH SYNOPSIS
33 .nf
34 .B #include <string.h>
35 .sp
36 .BI "char *strdup(const char *" s );
37 .sp
38 .BI "char *strndup(const char *" s ", size_t " n );
39 .br
40 .BI "char *strdupa(const char *" s );
41 .br
42 .BI "char *strndupa(const char *" s ", size_t " n );
43 .fi
44 .sp
45 .in -4n
46 Feature Test Macro Requirements for glibc (see
47 .BR feature_test_macros (7)):
48 .in
49 .PD 0
50 .ad l
51 .sp
52 .BR strdup ():
53 .RS 4
54 _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
55 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
56 .br
57 || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
58 .RE
59 .PP
60 .BR strndup ():
61 .RS 4
62 .TP 4
63 Since glibc 2.10:
64 POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700
65 .TP
66 Before glibc 2.10:
67 _GNU_SOURCE
68 .RE
69 .PP
70 .BR strdupa (),
71 .BR strndupa ():
72 _GNU_SOURCE
73 .ad
74 .PD
75 .SH DESCRIPTION
76 The
77 .BR strdup ()
78 function returns a pointer to a new string which
79 is a duplicate of the string \fIs\fP.
80 Memory for the new string is
81 obtained with
82 .BR malloc (3),
83 and can be freed with
84 .BR free (3).
85
86 The
87 .BR strndup ()
88 function is similar, but only copies at most
89 \fIn\fP characters.
90 If \fIs\fP is longer than \fIn\fP, only \fIn\fP
91 characters are copied, and a terminating null byte (\(aq\\0\(aq) is added.
92
93 .BR strdupa ()
94 and
95 .BR strndupa ()
96 are similar, but use
97 .BR alloca (3)
98 to allocate the buffer.
99 They are only available when using the GNU
100 GCC suite, and suffer from the same limitations described in
101 .BR alloca (3).
102 .SH "RETURN VALUE"
103 The
104 .BR strdup ()
105 function returns a pointer to the duplicated
106 string, or NULL if insufficient memory was available.
107 .SH ERRORS
108 .TP
109 .B ENOMEM
110 Insufficient memory available to allocate duplicate string.
111 .SH "CONFORMING TO"
112 .\" 4.3BSD-Reno, not (first) 4.3BSD.
113 .BR strdup ()
114 conforms to SVr4, 4.3BSD, POSIX.1-2001.
115 .BR strndup (),
116 .BR strdupa (),
117 and
118 .BR strndupa ()
119 are GNU extensions.
120 .SH "SEE ALSO"
121 .BR alloca (3),
122 .BR calloc (3),
123 .BR free (3),
124 .BR malloc (3),
125 .BR realloc (3),
126 .BR string (3),
127 .BR wcsdup (3)