.\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl) .\" .\" %%%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 .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1997-2000 Kazuyuki Tanisako and NAKANO Takeo .\" all rights reserved. .\" Translated 1997-05-17, Kazuyuki Tanisako .\" Modified 1997-05-27, Kazuyuki Tanisako .\" Modified 1998-02-04, Kazuyuki Tanisako .\" Updated and Modified 2000-10-12, NAKANO Takeo .\" Updated 2006-04-14, Akihiro MOTOKI , LDP v2.29 .\" Updated 2006-07-26, Akihiro MOTOKI , LDP v2.36 .\" Updated 2013-07-22, Akihiro MOTOKI .\" .TH TEMPNAM 3 2017\-09\-15 "" "Linux Programmer's Manual" .SH 名前 tempnam \- テンポラリファイルの名前を作成する .SH 書式 .nf \fB#include \fP .PP \fBchar *tempnam(const char *\fP\fIdir\fP\fB, const char *\fP\fIpfx\fP\fB);\fP .fi .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP \fBtempnam\fP(): Since glibc 2.19: _DEFAULT_SOURCE Glibc 2.19 and earlier: _BSD_SOURCE || _SVID_SOURCE .SH 説明 \fI決してこの関数を使用しないこと。\fP 代わりに \fBmkstemp\fP(3) か \fBtmpfile\fP(3) を使うこと。 .PP \fBtempnam\fP() 関数はファイル名として正しい文字列へのポインターを返す。 このファイル名を持つファイルは、 \fBtempnam\fP() がチェックした時点においては存在しない (しなかった)。 \fIpfx\fP が NULL でない 5 バイト以内の文字列であれば、 生成されるパス名のうちのファイル名の部分は \fIpfx\fP から始まるものになる。 生成されるディレクトリの部分は、「適切」でなければならない (大抵の場合、「適切」であるためにはまず少なくとも 書き込み可能でなければならない)。 .PP 適切なディレクトリの探索は、以下の手順にしたがって行われる。 .TP 3 a) 環境変数 \fBTMPDIR\fP が設定されていて、 その内容が適切なディレクトリの名前なら、それを用いる。 .TP b) それ以外の場合、 \fIdir\fP 引数が NULL でない文字列でかつ適切なら、それを用いる。 .TP c) それ以外の場合、 (\fI\fP で定義されている) \fIP_tmpdir\fP が適切なら、それを用いる。 .TP d) 最後に実装で定義されたディレクトリが用いられることになる。 .PP \fBtempnam\fP() が返す文字列は \fBmalloc\fP(3) を使って確保される。そのため、 \fBfree\fP(3) で解放すべきである。 .SH 返り値 成功すると \fBtempnam\fP() 関数は、一意なテンポラリファイル名へのポインターを返す。 一意な名前が生成できなければ NULL を返し、 \fIerrno\fP にエラーの原因を示す値を設定する。 .SH エラー .TP \fBENOMEM\fP 保存領域の割り当てに失敗した。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS allbox; lb lb lb l l l. インターフェース 属性 値 T{ \fBtempnam\fP() T} Thread safety MT\-Safe env .TE .SH 準拠 SVr4, 4.3BSD, POSIX.1\-2001. POSIX.1\-2008 は \fBtempnam\fP() を廃止予定としている。 .SH 注意 \fBtempnam\fP() は推測が難しい名前を生成するが、それにもかかわらず、 \fBtempnam\fP() がパス名を返してから、プログラムがそのファイルをオープンする までの間に、別のプログラムが同じパス名で、ファイルを \fBopen\fP(2) で作成したり、シンボリックリンクを作成したりする可能性がある。 これはセキュリティホールにつながる可能性がある。 そのような可能性を回避するためには、 \fBopen\fP(2) の \fBO_EXCL\fP フラグを使ってパス名をオープンすればよい。 もっといいのは、 \fBmkstemp\fP(3) や \fBtmpfile\fP(3) を使うことである。 .PP SUSv2 では \fBTMPDIR\fP に付いて言及されていない。 glibc は、プログラムが set\-user\-ID されていない場合に限ってこれを用いる。 SVr4 では \fBd)\fP で使用されるディレクトリを \fI/tmp\fP と定めている (glibc もこの通りである)。 .PP パス名を返すのに使用するメモリーを動的に確保するので、 \fBtmpnam\fP(3) と違い、 \fBtempnam\fP() はリエントラントであり、スレッドセーフである。 .PP \fBtempnam\fP() 関数は最大 \fBTMP_MAX\fP 回まで、呼び出される度に異なる文字列を作成する (\fBTMP_MAX\fP は \fI\fP で定義されている)。 もし \fBTMP_MAX\fP 回以上呼び出された場合、動作は実装依存である。 .PP \fBtempnam\fP() は最大で \fIpfx\fP の先頭 5 バイトを使用する。 .PP 他と重ならない名前が見つけられなかった場合、glibc の \fBtempnam\fP() の実装はエラー \fBEEXIST\fP で失敗する。 .SH バグ 「適切」という言葉の正確な意味は定義されていない。 ディレクトリに対してどの程度のアクセス権限が必要なのかは指定されていない。 .SH 関連項目 \fBmkstemp\fP(3), \fBmktemp\fP(3), \fBtmpfile\fP(3), \fBtmpnam\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。