.\" 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 .\" .\" Japanese Version Copyright (c) 1997 Kazuyuki Tanisako .\" all rights reserved. .\" Translated 1997-05-17, Kazuyuki Tanisako .\" Modified 1997-05-27, Kazuyuki Tanisako .\" Modified 1998-02-05, Kazuyuki Tanisako .\" Modified 1998-09-27, Kazuyuki Tanisako .\" Modified 1999-04-10, Kazuyuki Tanisako .\" Updated 2001-01-17, Kentaro Shirakata .\" Updated 2005-02-26, Akihiro MOTOKI .\" Updated 2008-08-10, Akihiro MOTOKI, LDP v3.05 .\" .\"WORD: temporary file 一時ファイル .\"WORD: read/write リード/ライト .\"WORD: permissions 許可 .\" .TH MKSTEMP 3 2008-06-19 "GNU" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O mkstemp, mkostemp \- create a unique temporary file mkstemp, mkostemp \- 他と重ならない名前を持つ一時ファイルを作成する .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .sp .BI "int mkstemp(char *" template ); .sp .BI "int mkostemp (char *" template ", int " flags ); .fi .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR mkstemp (): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 .br .BR mkostemp (): _GNU_SOURCE \"O .SH DESCRIPTION .SH 説明 .\"O The .\"O .BR mkstemp () .\"O function generates a unique temporary filename from .\"O .IR template , .\"O creates and opens the file, .\"O and returns an open file descriptor for the file. 関数 .BR mkstemp () は引数 .I template から他と重ならない一時ファイル名を生成し、 そのファイルの作成とオープンを行い、 そのファイルに対するオープン済みのファイルディスクリプタを返す。 .\"O The last six characters of .\"O .I template .\"O must be "XXXXXX" and these are replaced with a string that makes the .\"O filename unique. 引数 .I template で指示する文字列の後ろの 6 文字は XXXXXX である必要がある。 この部分がファイル名を他と重ならないようにする文字で置き換えられる。 .\"O Since it will be modified, .\"O .I template .\"O must not be a string constant, but should be declared as a character array. .I template は書き換えられるため、文字列定数ではなく文字配列として 宣言するようにしなければならない。 .\"O The file is created with .\"O permissions 0600, that is, read plus write for owner only. .\"O (In glibc versions 2.06 and earlier, the file is created with permissions 0666, .\"O that is, read and write for all users.) .\"O The returned file descriptor provides both read and write access to the file. .\"O The file is opened with the .\"O .BR open (2) .\"O .B O_EXCL .\"O flag, guaranteeing that the caller is the process that creates the file. ファイルは許可モード 0600 で作成され、所有者のみが読み書き可能である (glibc バージョン 2.06 以前では、ファイルは許可モード 0666 で作成され、 全てのユーザが読み書き可能であった)。 返されるファイルディスクリプタで、このファイルへの読み書き両方のアクセスが 可能である。 呼び出し者がそのファイルを作成するプロセスであることを保証するために、 ファイルは .BR open (2) の .B O_EXCL フラグ付きでオープンされる。 .\"O .BR mkostemp () .\"O is like .\"O .BR mkstemp (), .\"O with the difference that flags as for .\"O .BR open (2) .\"O may be specified in .\"O .IR flags .\"O (e.g., .\"O .BR O_APPEND , .\"O .BR O_SYNC ). .BR mkostemp () は .BR mkstemp () と同様だが、 .BR open (2) に渡されるフラグ .RB O_APPEND , .B O_SYNC など) を .I flags で指定できる点が異なる .\"O .SH "RETURN VALUE" .SH 返り値 .\"O On success, these functions return the file descriptor .\"O of the temporary file. .\"O On error, \-1 is returned, and .\"O .I errno .\"O is set appropriately. 成功すると、これらの関数は一時ファイルのファイルディスクリプタを返す。 エラーの場合は、\-1 を返し、 .I errno を適切に設定する。 .\"O .SH ERRORS .SH エラー .TP .B EEXIST .\"O Could not create a unique temporary filename. .\"O Now the contents of \fItemplate\fP are undefined. すでに同じ名前を持つファイルが存在した。 \fItemplate\fP の内容は不定である。 .TP .B EINVAL .\"O The last six characters of \fItemplate\fP were not XXXXXX. .\"O Now \fItemplate\fP is unchanged. 引数 \fItemplate\fP で指示された文字配列の後ろの 6 文字が XXXXXX でない。 \fItemplate\fP の内容は変化しない。 .PP .\"O These functions may also fail with any of the errors described for .\"O .BR open (2). これらの関数は .BR open (2) に書かわれているエラーのいずれかで失敗することもある。 .\"O .SH VERSIONS .SH バージョン .\"O .BR mkostemp () .\"O is available since glibc 2.7. .BR mkostemp () は glibc 2.7 以降で利用可能である。 .\"O .SH "CONFORMING TO" .SH 準拠 .BR mkstemp (): 4.3BSD, POSIX.1-2001. .BR mkostemp (): .\"O is a glibc extension. glibc による拡張。 .\"O .SH NOTES .SH 注意 .\"O The old behavior of creating a file with mode 0666 may be .\"O a security risk, especially since other Unix flavors use 0600, .\"O and somebody might overlook this detail when porting programs. 許可モード 0666 でファイルを作成するという古い動作は、 セキュリティ上のリスクになる場合がある。 特に他の Unix では許可モードとして 0600 を使うため、 プログラムを移植する際、この細かな違いを見落とす可能性が あるからだ。 .\"O More generally, the POSIX specification of .\"O .BR mkstemp () .\"O does not say anything .\"O about file modes, so the application should make sure its .\"O file mode creation mask (see .\"O .BR umask (2)) .\"O is set appropriately before calling .\"O .BR mkstemp () .\"O (and .\"O .BR mkostemp ()). より一般的には、 .BR mkstemp () の POSIX 規定ではファイルモードについて何も述べていない。 従って、アプリケーションは .BR mkstemp () (や .BR mkostemp ()) を呼び出す前にファイルモード生成マスク .RB ( umask (2) 参照) が適切に設定されているか確認するべきである。 .\"O The prototype for .\"O .BR mktemp () .\"O is in .\"O .I .\"O for libc4, libc5, glibc1; glibc2 follows POSIX.1 and has the prototype in .\"O .IR . .BR mktemp () のプロトタイプ宣言は、libc4, libc5, glibc1 では .I に含まれる; glibc2 では POSIX.1 に準拠し .I に含まれている。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR mkdtemp (3), .BR mktemp (3), .BR tempnam (3), .BR tmpfile (3), .BR tmpnam (3)