.\" 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 .\" .\" 2003-11-15, aeb, added tmpnam_r .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright 1997 Tenkou N. Hattori .\" Japanese Version Copyright (c) 1997 Tenkou N. Hattori .\" all rights reserved. .\" Translated 1997-01-18, Tenkou N. Hattori .\" Updated 2000-03-15, Kentaro Shirakata .\" Updated 2005-03-15, Akihiro MOTOKI .\" Updated 2006-07-26, Akihiro MOTOKI , LDP v2.36 .\" .TH TMPNAM 3 2014\-02\-27 "" "Linux Programmer's Manual" .SH 名前 tmpnam, tmpnam_r \- 一時ファイルの名前を作成する .SH 書式 .nf \fB#include \fP .sp \fBchar *tmpnam(char *\fP\fIs\fP\fB);\fP .fi .SH 説明 \fB注意:\fP \fBtmpnam\fP() の使用は避けること。代わりに \fBmkstemp\fP(3) か \fBtmpfile\fP(3) を使うこと。 \fBtmpnam\fP() 関数は、ファイル名に使える文字列へのポインターを返す。 ある時点では同じ名前を持つファイルが存在しないファイル名が返されるので、 幼稚なプログラマはこの文字列が一時ファイルのファイル名として 適していると考えるかもしれない。 引き数 \fIs\fP が NULL なら、この名前は内部の静的バッファーに作成され、 次に \fBtmpnam\fP() 関数が呼び出された時に上書きされる。 \fIs\fP が NULL でなければ、ファイル名は \fIs\fP が指す (少なくとも \fIL_tmpnam\fP の長さを持つ) 文字配列にコピーされ、 成功した場合は \fIs\fP が返される。 .LP 作成されるパス名は、ディレクトリの部分に \fIP_tmpdir\fP が使われる。 (\fIL_tmpnam\fP と \fIP_tmpdir\fP は、以下で説明する \fBTMP_MAX\fP 同様 \fI\fP で定義されている。) .SH 返り値 \fBtmpnam\fP() 関数は一意な一時ファイル名へのポインターを返す。 一意なファイル名が作成できなかった場合は NULL を返す。 .SH エラー エラーは定義されていない。 .SH 属性 .SS "マルチスレッディング (pthreads(7) 参照)" \fBtmpnam\fP() 関数は例外付きでスレッドセーフである。 NULL パラメーターで呼び出された場合はスレッドセーフではない。 .LP \fBtmpnam_r\fP() 関数はスレッドセーフである。 .SH 準拠 SVr4, 4.3BSD, C89, C99, POSIX.1\-2001. POSIX.1\-2008 は \fBtmpnam\fP() を廃止予定としている。 .SH 注意 \fBtmpnam\fP() 関数は最大 \fBTMP_MAX\fP 回まで、呼び出される度に異なる文字列を作成する。 \fBTMP_MAX\fP 回以上呼び出された場合、その動作は実装依存である。 .LP \fBtmpnam\fP() は推測が難しい名前を生成するが、それにもかかわらず、 \fBtmpnam\fP() がパス名を返してから、プログラムがそのファイルをオープンする までの間に、別のプログラムが同じパス名で、ファイルを \fBopen\fP(2) で作成したり、シンボリックリンクを作成したりする可能性がある。 これはセキュリティホールにつながる可能性がある。 そのような可能性を回避するためには、 \fBopen\fP(2) の \fBO_EXCL\fP フラグを使ってパス名をオープンすればよい。 もっといいのは、 \fBmkstemp\fP(3) や \fBtmpfile\fP(3) を使うことである。 .LP 移植性が必要な、スレッドを使ったアプリケーションでは、 \fB_POSIX_THREADS\fP か \fB_POSIX_THREAD_SAFE_FUNCTIONS\fP が定義されている場合に、 \fBtmpnam\fP() 関数を NULL 引き数で呼び出してはならない。 .LP POSIX 草案では、関数 \fBtmpnam_r\fP() を使うことを提案している。 この関数は、以下のように定義されており、 NULL を使わないようにという警告の意味で NULL を別扱いしている。 .sp .nf .in +4n char * tmpnam_r(char *s) { return s ? tmpnam(s) : NULL; } .in .fi .sp 数は少ないが、この関数を実装しているシステムもある。 この関数の glibc のプロトタイプを \fI\fP から得るには、 (「どの」ヘッダーファイルをインクルードするよりも前に) \fB_SVID_SOURCE\fP か \fB_BSD_SOURCE\fP を定義しておく必要がある。 .SH バグ 決してこの関数を使ってはならない。代わりに \fBmkstemp\fP(3) か \fBtmpfile\fP(3) を使うこと。 .SH 関連項目 \fBmkstemp\fP(3), \fBmktemp\fP(3), \fBtempnam\fP(3), \fBtmpfile\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。