.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Sun Jul 25 10:41:34 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified Wed Oct 17 01:12:26 2001 by John Levon .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi .\" all rights reserved. .\" Translated Mon Jan 20 22:31:05 JST 1997 .\" by YOSHINO Takashi .\" Updated Fri Nov 2 JST 2001 by Kentaro Shirakata .\" Updated 2013-07-22, Akihiro MOTOKI .\" .TH STRDUP 3 2019\-03\-06 GNU "Linux Programmer's Manual" .SH 名前 strdup, strndup, strdupa, strndupa \- 文字列を複製する .SH 書式 .nf \fB#include \fP .PP \fBchar *strdup(const char *\fP\fIs\fP\fB);\fP .PP \fBchar *strndup(const char *\fP\fIs\fP\fB, size_t \fP\fIn\fP\fB);\fP \fBchar *strdupa(const char *\fP\fIs\fP\fB);\fP \fBchar *strndupa(const char *\fP\fIs\fP\fB, size_t \fP\fIn\fP\fB);\fP .fi .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP .PD 0 .ad l \fBstrdup\fP(): .RS 4 .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED _XOPEN_SOURCE\ >=\ 500 || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE .RE .PP \fBstrndup\fP(): .RS 4 .TP 4 glibc 2.10 以降: _POSIX_C_SOURCE\ >=\ 200809L .TP glibc 2.10 より前: _GNU_SOURCE .RE .PP \fBstrdupa\fP(), \fBstrndupa\fP(): _GNU_SOURCE .ad .PD .SH 説明 \fBstrdup\fP() 関数は、文字列 \fIs\fPの複製である 新しい文字列へのポインターを返す。 新しい文字列のためのメモリーは \fBmalloc\fP(3) で得ている。 そして、 \fBfree\fP(3) で解放することができる。 .PP \fBstrndup\fP() 関数は同様であるが、最大で \fIn\fP バイトを複製する。 \fIs\fP が \fIn\fP よりも長い場合、\fIn\fP バイトだけが複製され、 終端のヌルバイト (\(aq\e0\(aq)) が追加される。 .PP \fBstrdupa\fP() と \fBstrndupa\fP() も同様だが、バッファーの確保に \fBalloca\fP(3) を使用する点が異なる。 これらが使用できるのは GNU GCC ツール群を使う場合だけであり、 \fBalloca\fP(3) で説明されているのと同じ制限がある。 .SH 返り値 成功すると、 \fBstrdup\fP() 関数は複製された文字列へのポインターを返す。 十分なメモリーが確保できなかった場合には、 NULL を返し、 \fIerrno\fP にエラーの原因を示す値を設定する。 .SH エラー .TP \fBENOMEM\fP 複製された文字列を割り当てる十分なメモリーが確保できなかった。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS allbox; lbw31 lb lb l l l. インターフェース 属性 値 T{ \fBstrdup\fP(), \fBstrndup\fP(), \fBstrdupa\fP(), .br \fBstrndupa\fP() T} Thread safety MT\-Safe .TE .sp 1 .SH 準拠 .\" 4.3BSD-Reno, not (first) 4.3BSD. \fBstrdup\fP() は SVr4, 4.3BSD, POSIX.1\-2001 準拠である。 \fBstrndup\fP() は POSIX.1\-2008 準拠である。 \fBstrdupa\fP(), \fBstrndupa\fP() は GNU 拡張である。 .SH 関連項目 \fBalloca\fP(3), \fBcalloc\fP(3), \fBfree\fP(3), \fBmalloc\fP(3), \fBrealloc\fP(3), \fBstring\fP(3), \fBwcsdup\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。