.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" and Copyright (C) 2008, Michael Kerrisk .\" .\" 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. .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Sat Jul 24 18:48:48 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified 980310, aeb .\" Modified 990328, aeb .\" 2008-06-19, mtk, Added mkostemp(); various other changes .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH MKSTEMP 3 2012\-04\-21 GNU "Linux Programmer's Manual" .SH 名前 mkstemp, mkostemp, mkstemps, mkostemps \- 他と重ならない名前を持つ一時ファイルを作成する .SH 書式 .nf \fB#include \fP .sp \fBint mkstemp(char *\fP\fItemplate\fP\fB);\fP .sp \fBint mkostemp(char *\fP\fItemplate\fP\fB, int \fP\fIflags\fP\fB);\fP .sp \fBint mkstemps(char *\fP\fItemplate\fP\fB, int \fP\fIsuffixlen\fP\fB);\fP .sp \fBint mkostemps(char *\fP\fItemplate\fP\fB, int \fP\fIsuffixlen\fP\fB, int \fP\fIflags\fP\fB);\fP .fi .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .sp \fBmkstemp\fP(): .ad l .RS 4 .PD 0 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED .br || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200112L .PD .RE .ad b .PP \fBmkostemp\fP(): _GNU_SOURCE .br \fBmkstemps\fP(): _BSD_SOURCE || _SVID_SOURCE .br \fBmkostemps\fP(): _GNU_SOURCE .SH 説明 関数 \fBmkstemp\fP() は引数 \fItemplate\fP から他と重ならない一時ファイル名を生成し、 そのファイルの作成とオープンを行い、 そのファイルに対するオープン済みのファイルディスクリプタを返す。 引数 \fItemplate\fP で指示する文字列の後ろの 6 文字は XXXXXX である必要がある。 この部分がファイル名を他と重ならないようにする文字で置き換えられる。 \fItemplate\fP は書き換えられるため、文字列定数ではなく文字配列として 宣言するようにしなければならない。 ファイルは許可モード 0600 で作成され、所有者のみが読み書き可能である (glibc バージョン 2.06 以前では、ファイルは許可モード 0666 で作成され、 全てのユーザが読み書き可能であった)。 返されるファイルディスクリプタで、このファイルへの読み書き両方のアクセスが 可能である。 呼び出し者がそのファイルを作成するプロセスであることを保証するために、 ファイルは \fBopen\fP(2) の \fBO_EXCL\fP フラグ付きでオープンされる。 \fBmkostemp\fP() 関数は \fBmkstemp\fP() と同様だが、\fBopen\fP(2) に渡される フラグ O_APPEND\fB,\fP \fBO_SYNC\fP など) を \fIflags\fP で指定できる点が異なる \fBmkstemps\fP() 関数は \fBmkstemp\fP() と同様だが、 \fItemplate\fP 内の文字列に長さ が \fIsuffixlen\fP 文字の接尾辞 (suffix) が含まれる点が異なる。 したがって、 \fItemplate\fP は \fIprefixXXXXXXsuffix\fP の形式となる。 文字列 XXXXXX の部分は \fBmkstemp\fP() により更新される。 \fBmkostemps\fP() と \fBmkstemps\fP() の関係は、 \fBmkostemp\fP() と \fBmkstemp\fP() の関係と同じである。 .SH 返り値 成功すると、これらの関数は一時ファイルのファイルディスクリプタを返す。 エラーの場合は、\-1 を返し、 \fIerrno\fP を適切に設定する。 .SH エラー .TP \fBEEXIST\fP すでに同じ名前を持つファイルが存在した。 \fItemplate\fP の内容は不定である。 .TP \fBEINVAL\fP \fBmkstemp\fP() と \fBmkostemp\fP() の場合: \fItemplate\fP の最後の 6 文字が XXXXXX でなかった。 この場合、\fItemplate\fP は変更されない。 .sp \fBmkstemps\fP() と \fBmkostemps\fP() の場合: \fItemplate\fP の長さが \fI(6 + suffixlen)\fP 文字より短い、または \fItemplate\fP の接尾辞の直前の 6 文字が XXXXXX ではなかった。 .PP これらの関数は \fBopen\fP(2) に書かれているエラーのいずれかで失敗することもある。 .SH バージョン \fBmkostemp\fP() は glibc 2.7 以降で利用できる。 \fBmkstemps\fP() と \fBmkostemps\fP() は glibc 2.11 以降で利用できる。 .SH 準拠 \fBmkstemp\fP(): 4.3BSD, POSIX.1\-2001. .\" mkstemps() appears to be at least on the BSDs, Mac OS X, Solaris, .\" and Tru64. \fBmkstemps\fP(): 標準化されていないが、他のいくつかのシステムにも存在する。 \fBmkostemp\fP() と \fBmkostemps\fP(): glibc による拡張。 .SH 注意 許可モード 0666 でファイルを作成するという古い動作は、 セキュリティ上のリスク になる場合がある。 特に他の UNIX では許可モードとして 0600 を使うため、 プログラムを移植する際、この細かな違いを見落とす可能性があるからだ。 より一般的には、 \fBmkstemp\fP() の POSIX 規定ではファイルモードについて何も述べていない。 従って、アプリケーションは \fBmkstemp\fP() (や \fBmkostemp\fP()) を呼び出す前にファイルモード生成マスク (\fBumask\fP(2) 参照) が適切に設定されているか確認するべきである。 \fBmktemp\fP() のプロトタイプ宣言は、libc4, libc5, glibc1 では \fI\fP に含まれる; glibc2 では POSIX.1 に準拠し \fI\fP に含まれている。 .SH 関連項目 \fBmkdtemp\fP(3), \fBmktemp\fP(3), \fBtempnam\fP(3), \fBtmpfile\fP(3), \fBtmpnam\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.41 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。