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