Debian Codegraph @

upstream/debian-unstable/man3/strdupa.3

raw
1 '\" t
2 .\" Copyright 1993, David Metcalfe <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH strdupa 3 2026-02-25 "Linux man-pages 6.18"
8 .SH NAME
9 strdupa, strndupa \- string duplicate using alloca
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
16 .B #include <string.h>
17 .P
18 .BI "char *strdupa(const char *" s );
19 .BR "char *strndupa(" "size_t n;"
20 .BI " const char " s [ n "], size_t " n );
21 .fi
22 .SH DESCRIPTION
23 .TP
24 .BR strdupa ()
25 .BR strdupa ()
26 is similar to
27 .BR strdup (3),
28 but uses
29 .BR alloca (3)
30 to allocate the buffer.
31 .IP
32 It is equivalent to
33 .IP
34 .in +4n
35 .EX
36 strcpy(alloca(strlen(s) + 1), s)
37 .EE
38 .in
39 .TP
40 .BR strndupa ()
41 .BR strndupa ()
42 is similar to
43 .BR strndupa (3),
44 but uses
45 .BR alloca (3)
46 to allocate the buffer.
47 .IP
48 It is equivalent to
49 .IP
50 .in +4n
51 .EX
52 strncat(strcpy(alloca(n + 1), ""), s, n)
53 .EE
54 .in
55 .SH RETURN VALUE
56 On success,
57 these macros return
58 a pointer to the duplicated string.
59 .SH ATTRIBUTES
60 For an explanation of the terms used in this section, see
61 .BR attributes (7).
62 .TS
63 allbox;
64 lbx lb lb
65 l l l.
66 Interface Attribute Value
67 T{
68 .na
69 .nh
70 .BR strdupa (),
71 .BR strndupa ()
72 T} Thread safety MT-Safe
73 .TE
74 .SH STANDARDS
75 GNU.
76 .SH HISTORY
77 GNU.
78 .SH SEE ALSO
79 .BR alloca (3),
80 .BR strdup (3),
81 .BR strndup (3)