.\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl) .\" Japanese Version Copyright 1997 Tenkou N. Hattori .\" .\" 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. .\" .\" 2003-11-15, aeb, added tmpnam_r .\" .\" 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 2008-08-06 "" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O tmpnam, tmpnam_r \- create a name for a temporary file tmpnam, tmpnam_r \- 一時ファイルの名前を作成する .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .sp .BI "char *tmpnam(char *" s ); .fi .\"O .SH DESCRIPTION .SH 説明 .\"O The .\"O .BR tmpnam () .\"O function returns a pointer to a string that is a valid filename, .\"O and such that a file with this name did not exist at some point .\"O in time, so that naive programmers may think it .\"O a suitable name for a temporary file. .\"O If the argument .\"O .I s .\"O is NULL this name is generated in an internal static buffer .\"O and may be overwritten by the next call to .\"O .BR tmpnam (). .BR tmpnam () 関数は、ファイル名に使える文字列へのポインタを返す。 ある時点では同じ名前を持つファイルが存在しないファイル名が返されるので、 幼稚なプログラマはこの文字列が一時ファイルのファイル名として 適していると考えるかもしれない。 引き数 .I s が NULL なら、この名前は内部の静的バッファに作成され、 次に .BR tmpnam () 関数が呼び出された時に上書きされる。 .\"O If .\"O .I s .\"O is not NULL, the name is copied to the character array (of length .\"O at least .\"O .IR L_tmpnam ) .\"O pointed to by .\"O .I s .\"O and the value .\"O .I s .\"O is returned in case of success. .I s が NULL でなければ、ファイル名は .I s が指す (少なくとも .I L_tmpnam の長さを持つ) 文字配列にコピーされ、 成功した場合は .I s が返される。 .LP .\"O The pathname that is created, has a directory prefix .\"O .IR P_tmpdir . 作成されるパス名は、ディレクトリの部分に .I P_tmpdir が使われる。 .\"O (Both .\"O .I L_tmpnam .\"O and .\"O .I P_tmpdir .\"O are defined in .\"O .IR , .\"O just like the .\"O .B TMP_MAX .\"O mentioned below.) .RI ( L_tmpnam と .I P_tmpdir は、以下で説明する .B TMP_MAX 同様 .I で定義されている。) .\"O .SH "RETURN VALUE" .SH 返り値 .\"O The .\"O .BR tmpnam () .\"O function returns a pointer to a unique temporary .\"O filename, or NULL if a unique name cannot be generated. .BR tmpnam () 関数は一意な一時ファイル名へのポインタを返す。 一意なファイル名が作成できなかった場合は NULL を返す。 .SH エラー .\"O No errors are defined. エラーは定義されていない。 .\"O .SH "CONFORMING TO" .SH 準拠 SVr4, 4.3BSD, C89, C99, POSIX.1-2001. .\"O POSIX.1-2008 marks .\"O .BR tmpnam () .\"O as obsolete. POSIX.1-2008 は .BR tmpnam () を廃止予定としている。 .\"O .SH NOTES .SH 注意 .\"O The .\"O .BR tmpnam () .\"O function generates a different string each time it is called, .\"O up to .\"O .B TMP_MAX .\"O times. .\"O If it is called more than .\"O .B TMP_MAX .\"O times, .\"O the behavior is implementation defined. .BR tmpnam () 関数は最大 .B TMP_MAX 回まで、呼び出される度に異なる文字列を作成する。 .B TMP_MAX 回以上呼び出された場合、その動作は実装依存である。 .LP .\"O Although .\"O .BR tmpnam () .\"O generates names that are difficult to guess, .\"O it is nevertheless possible that between the time that .\"O .BR tmpnam () .\"O returns a pathname, and the time that the program opens it, .\"O another program might create that pathname using .\"O .BR open (2), .\"O or create it as a symbolic link. .\"O This can lead to security holes. .\"O To avoid such possibilities, use the .\"O .BR open (2) .\"O .B O_EXCL .\"O flag to open the pathname. .\"O Or better yet, use .\"O .BR mkstemp (3) .\"O or .\"O .BR tmpfile (3). .BR tmpnam () は推測が難しい名前を生成するが、それにもかかわらず、 .BR tmpnam () がパス名を返してから、プログラムがそのファイルをオープンする までの間に、別のプログラムが同じパス名で、ファイルを .BR open (2) で作成したり、シンボリックリンクを作成したりする可能性がある。 これはセキュリティホールにつながる可能性がある。 そのような可能性を回避するためには、 .BR open (2) の .B O_EXCL フラグを使ってパス名をオープンすればよい。 もっといいのは、 .BR mkstemp (3) や .BR tmpfile (3) を使うことである。 .LP .\"O Portable applications that use threads cannot call .\"O .BR tmpnam () .\"O with a NULL parameter if either .\"O .B _POSIX_THREADS .\"O or .\"O .B _POSIX_THREAD_SAFE_FUNCTIONS .\"O is defined. 移植性が必要な、スレッドを使ったアプリケーションでは、 .B _POSIX_THREADS か .B _POSIX_THREAD_SAFE_FUNCTIONS が定義されている場合に、 .BR tmpnam () 関数を NULL 引き数で呼び出してはならない。 .LP .\"O A POSIX draft proposed to use a function .\"O .BR tmpnam_r () .\"O defined by .\"O .sp .\"O .nf .\"O .in +4n .\"O char *tmpnam_r(char *s) { .\"O return s ? tmpnam(s) : NULL; .\"O } .\"O .in .\"O .fi .\"O .sp .\"O apparently as a warning not to use NULL. POSIX 草案では、関数 .BR tmpnam_r () を使うことを提案している。 この関数は、以下のように定義されており、 NULL を使わないようにという警告の意味で NULL を別扱いしている。 .sp .nf .in +4n char * tmpnam_r(char *s) { return s ? tmpnam(s) : NULL; } .in .fi .sp .\"O A few systems implement it. .\"O To get a glibc prototype for this function, .\"O define .\"O .B _SVID_SOURCE .\"O or .\"O .B _BSD_SOURCE .\"O before including .\"O .IR . 数は少ないが、この関数を実装しているシステムもある。 この関数の glibc のプロトタイプを使うには、 .I をインクルードする前に .B _SVID_SOURCE か .B _BSD_SOURCE を定義しておく必要がある。 .\"O .SH BUGS .SH バグ .\"O Never use this function. .\"O Use .\"O .BR mkstemp (3) .\"O or .\"O .BR tmpfile (3) .\"O instead. 決してこの関数を使ってはならない。代わりに .BR mkstemp (3) か .BR tmpfile (3) を使うこと。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR mkstemp (3), .BR mktemp (3), .BR tempnam (3), .BR tmpfile (3)