OSDN Git Service

3261efc8fad88935bf252aa3f534e33c01d6f554
[linuxjm/LDP_man-pages.git] / release / man3 / mkstemp.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2008, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" References consulted:
27 .\"     Linux libc source code
28 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
29 .\"     386BSD man pages
30 .\" Modified Sat Jul 24 18:48:48 1993 by Rik Faith (faith@cs.unc.edu)
31 .\" Modified 980310, aeb
32 .\" Modified 990328, aeb
33 .\" 2008-06-19, mtk, Added mkostemp(); various other changes
34 .\"
35 .\"*******************************************************************
36 .\"
37 .\" This file was generated with po4a. Translate the source file.
38 .\"
39 .\"*******************************************************************
40 .TH MKSTEMP 3 2012\-12\-21 GNU "Linux Programmer's Manual"
41 .SH 名前
42 mkstemp, mkostemp, mkstemps, mkostemps \- 他と重ならない名前を持つ一時ファイルを作成する
43 .SH 書式
44 .nf
45 \fB#include <stdlib.h>\fP
46 .sp
47 \fBint mkstemp(char *\fP\fItemplate\fP\fB);\fP
48 .sp
49 \fBint mkostemp(char *\fP\fItemplate\fP\fB, int \fP\fIflags\fP\fB);\fP
50 .sp
51 \fBint mkstemps(char *\fP\fItemplate\fP\fB, int \fP\fIsuffixlen\fP\fB);\fP
52 .sp
53 \fBint mkostemps(char *\fP\fItemplate\fP\fB, int \fP\fIsuffixlen\fP\fB, int \fP\fIflags\fP\fB);\fP
54 .fi
55 .sp
56 .in -4n
57 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
58 .in
59 .sp
60 \fBmkstemp\fP():
61 .ad l
62 .RS 4
63 .PD 0
64 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
65 .br
66 || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200112L
67 .PD
68 .RE
69 .ad b
70 .PP
71 \fBmkostemp\fP(): _GNU_SOURCE
72 .br
73 \fBmkstemps\fP(): _BSD_SOURCE || _SVID_SOURCE
74 .br
75 \fBmkostemps\fP(): _GNU_SOURCE
76 .SH 説明
77 関数 \fBmkstemp\fP()  は引数 \fItemplate\fP から他と重ならない一時ファイル名を生成し、 そのファイルの作成とオープンを行い、
78 そのファイルに対するオープン済みのファイルディスクリプタを返す。
79
80 引数 \fItemplate\fP で指示する文字列の後ろの 6 文字は XXXXXX である必要がある。
81 この部分がファイル名を他と重ならないようにする文字で置き換えられる。 \fItemplate\fP は書き換えられるため、文字列定数ではなく文字配列として
82 宣言するようにしなければならない。
83
84 ファイルは許可モード 0600 で作成され、所有者のみが読み書き可能である。返されるファイルディスクリプタで、このファイルへの読み書き両方のアクセスが
85 可能である。 呼び出し者がそのファイルを作成するプロセスであることを保証するために、 ファイルは \fBopen\fP(2)  の \fBO_EXCL\fP
86 フラグ付きでオープンされる。
87
88 \fBmkostemp\fP() 関数は \fBmkstemp\fP() と同様だが、\fBopen\fP(2) に渡される
89 フラグ O_APPEND\fB,\fP \fBO_SYNC\fP など) を \fIflags\fP で指定できる点が異なる
90
91 \fBmkstemps\fP() 関数は \fBmkstemp\fP() と同様だが、 \fItemplate\fP 内の文字列に長さ
92 が \fIsuffixlen\fP 文字の接尾辞 (suffix) が含まれる点が異なる。
93 したがって、 \fItemplate\fP は \fIprefixXXXXXXsuffix\fP の形式となる。
94 文字列 XXXXXX の部分は \fBmkstemp\fP() により更新される。
95
96 \fBmkostemps\fP() と \fBmkstemps\fP() の関係は、
97 \fBmkostemp\fP() と \fBmkstemp\fP() の関係と同じである。
98 .SH 返り値
99 成功すると、これらの関数は一時ファイルのファイルディスクリプタを返す。 エラーの場合は、\-1 を返し、 \fIerrno\fP を適切に設定する。
100 .SH エラー
101 .TP 
102 \fBEEXIST\fP
103 すでに同じ名前を持つファイルが存在した。 \fItemplate\fP の内容は不定である。
104 .TP 
105 \fBEINVAL\fP
106 \fBmkstemp\fP() と \fBmkostemp\fP() の場合:
107 \fItemplate\fP の最後の 6 文字が XXXXXX でなかった。
108 この場合、\fItemplate\fP は変更されない。
109 .sp
110 \fBmkstemps\fP() と \fBmkostemps\fP() の場合:
111 \fItemplate\fP の長さが \fI(6 + suffixlen)\fP 文字より短い、または
112 \fItemplate\fP の接尾辞の直前の 6 文字が XXXXXX ではなかった。
113 .PP
114 これらの関数は \fBopen\fP(2) に書かれているエラーのいずれかで失敗することもある。
115 .SH バージョン
116 \fBmkostemp\fP() は glibc 2.7 以降で利用できる。
117 \fBmkstemps\fP() と \fBmkostemps\fP() は glibc 2.11 以降で利用できる。
118 .SH 準拠
119 \fBmkstemp\fP(): 4.3BSD, POSIX.1\-2001.
120
121 .\" mkstemps() appears to be at least on the BSDs, Mac OS X, Solaris,
122 .\" and Tru64.
123 \fBmkstemps\fP(): 標準化されていないが、他のいくつかのシステムにも存在する。
124
125 \fBmkostemp\fP() と \fBmkostemps\fP(): glibc による拡張。
126 .SH 注意
127 glibc バージョン 2.06 以前では、ファイルは許可モード 0666 で作成され、全てのユーザが読み書き可能であった。この古い動作は、
128 セキュリティ上のリスクになり得る。特に、他の UNIX では許可モードとして 0600
129 を使うため、プログラムを移植する際、この細かな違いを見落とす可能性があるからだ。 POSIX.1\-2008 では、ファイルを許可モード 0600
130 で作成することが必須要件として追加された。
131
132 より一般的には、 \fBmkstemp\fP()  の POSIX 規定ではファイルモードについて何も述べていない。 従って、アプリケーションは
133 \fBmkstemp\fP()  (や \fBmkostemp\fP())  を呼び出す前にファイルモード生成マスク (\fBumask\fP(2)  参照)
134 が適切に設定されているか確認するべきである。
135
136 \fBmktemp\fP()  のプロトタイプ宣言は、libc4, libc5, glibc1 では \fI<unistd.h>\fP に含まれる;
137 glibc2 では POSIX.1 に準拠し \fI<stdlib.h>\fP に含まれている。
138 .SH 関連項目
139 \fBmkdtemp\fP(3), \fBmktemp\fP(3), \fBtempnam\fP(3), \fBtmpfile\fP(3), \fBtmpnam\fP(3)
140 .SH この文書について
141 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
142 である。プロジェクトの説明とバグ報告に関する情報は
143 http://www.kernel.org/doc/man\-pages/ に書かれている。