OSDN Git Service

(split) LDP: Restore and add Copyrights for draft pages
[linuxjm/LDP_man-pages.git] / draft / 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 .\"
41 .\" Japanese Version Copyright (c) 1997 Kazuyuki Tanisako
42 .\"         all rights reserved.
43 .\" Translated 1997-05-17, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
44 .\" Modified 1997-05-27, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
45 .\" Modified 1998-02-05, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
46 .\" Modified 1998-09-27, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
47 .\" Modified 1999-04-10, Kazuyuki Tanisako <tanisako@osa.dec.com>
48 .\" Updated 2001-01-17, Kentaro Shirakata <argrath@ub32.org>
49 .\" Updated 2005-02-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
50 .\" Updated 2008-08-10, Akihiro MOTOKI, LDP v3.05
51 .\" Updated 2012-04-27, Akihiro MOTOKI <amotoki@gmail.com>
52 .\" Updated 2012-05-01, Akihiro MOTOKI <amotoki@gmail.com>
53 .\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
54 .\"
55 .TH MKSTEMP 3 2012\-12\-21 GNU "Linux Programmer's Manual"
56 .SH 名前
57 mkstemp, mkostemp, mkstemps, mkostemps \- 他と重ならない名前を持つ一時ファイルを作成する
58 .SH 書式
59 .nf
60 \fB#include <stdlib.h>\fP
61 .sp
62 \fBint mkstemp(char *\fP\fItemplate\fP\fB);\fP
63 .sp
64 \fBint mkostemp(char *\fP\fItemplate\fP\fB, int \fP\fIflags\fP\fB);\fP
65 .sp
66 \fBint mkstemps(char *\fP\fItemplate\fP\fB, int \fP\fIsuffixlen\fP\fB);\fP
67 .sp
68 \fBint mkostemps(char *\fP\fItemplate\fP\fB, int \fP\fIsuffixlen\fP\fB, int \fP\fIflags\fP\fB);\fP
69 .fi
70 .sp
71 .in -4n
72 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
73 .in
74 .sp
75 \fBmkstemp\fP():
76 .ad l
77 .RS 4
78 .PD 0
79 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
80 .br
81 || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200112L
82 .PD
83 .RE
84 .ad b
85 .PP
86 \fBmkostemp\fP(): _GNU_SOURCE
87 .br
88 \fBmkstemps\fP(): _BSD_SOURCE || _SVID_SOURCE
89 .br
90 \fBmkostemps\fP(): _GNU_SOURCE
91 .SH 説明
92 関数 \fBmkstemp\fP()  は引数 \fItemplate\fP から他と重ならない一時ファイル名を生成し、 そのファイルの作成とオープンを行い、
93 そのファイルに対するオープン済みのファイルディスクリプタを返す。
94
95 引数 \fItemplate\fP で指示する文字列の後ろの 6 文字は XXXXXX である必要がある。
96 この部分がファイル名を他と重ならないようにする文字で置き換えられる。 \fItemplate\fP は書き換えられるため、文字列定数ではなく文字配列として
97 宣言するようにしなければならない。
98
99 ファイルは許可モード 0600 で作成され、所有者のみが読み書き可能である。返されるファイルディスクリプタで、このファイルへの読み書き両方のアクセスが
100 可能である。 呼び出し者がそのファイルを作成するプロセスであることを保証するために、 ファイルは \fBopen\fP(2)  の \fBO_EXCL\fP
101 フラグ付きでオープンされる。
102
103 \fBmkostemp\fP() 関数は \fBmkstemp\fP() と同様だが、\fBopen\fP(2) に渡される
104 フラグ O_APPEND\fB,\fP \fBO_SYNC\fP など) を \fIflags\fP で指定できる点が異なる
105
106 \fBmkstemps\fP() 関数は \fBmkstemp\fP() と同様だが、 \fItemplate\fP 内の文字列に長さ
107 が \fIsuffixlen\fP 文字の接尾辞 (suffix) が含まれる点が異なる。
108 したがって、 \fItemplate\fP は \fIprefixXXXXXXsuffix\fP の形式となる。
109 文字列 XXXXXX の部分は \fBmkstemp\fP() により更新される。
110
111 \fBmkostemps\fP() と \fBmkstemps\fP() の関係は、
112 \fBmkostemp\fP() と \fBmkstemp\fP() の関係と同じである。
113 .SH 返り値
114 成功すると、これらの関数は一時ファイルのファイルディスクリプタを返す。 エラーの場合は、\-1 を返し、 \fIerrno\fP を適切に設定する。
115 .SH エラー
116 .TP 
117 \fBEEXIST\fP
118 すでに同じ名前を持つファイルが存在した。 \fItemplate\fP の内容は不定である。
119 .TP 
120 \fBEINVAL\fP
121 \fBmkstemp\fP() と \fBmkostemp\fP() の場合:
122 \fItemplate\fP の最後の 6 文字が XXXXXX でなかった。
123 この場合、\fItemplate\fP は変更されない。
124 .sp
125 \fBmkstemps\fP() と \fBmkostemps\fP() の場合:
126 \fItemplate\fP の長さが \fI(6 + suffixlen)\fP 文字より短い、または
127 \fItemplate\fP の接尾辞の直前の 6 文字が XXXXXX ではなかった。
128 .PP
129 これらの関数は \fBopen\fP(2) に書かれているエラーのいずれかで失敗することもある。
130 .SH バージョン
131 \fBmkostemp\fP() は glibc 2.7 以降で利用できる。
132 \fBmkstemps\fP() と \fBmkostemps\fP() は glibc 2.11 以降で利用できる。
133 .SH 準拠
134 \fBmkstemp\fP(): 4.3BSD, POSIX.1\-2001.
135
136 .\" mkstemps() appears to be at least on the BSDs, Mac OS X, Solaris,
137 .\" and Tru64.
138 \fBmkstemps\fP(): 標準化されていないが、他のいくつかのシステムにも存在する。
139
140 \fBmkostemp\fP() と \fBmkostemps\fP(): glibc による拡張。
141 .SH 注意
142 glibc バージョン 2.06 以前では、ファイルは許可モード 0666 で作成され、全てのユーザが読み書き可能であった。この古い動作は、
143 セキュリティ上のリスクになり得る。特に、他の UNIX では許可モードとして 0600
144 を使うため、プログラムを移植する際、この細かな違いを見落とす可能性があるからだ。 POSIX.1\-2008 では、ファイルを許可モード 0600
145 で作成することが必須要件として追加された。
146
147 より一般的には、 \fBmkstemp\fP()  の POSIX 規定ではファイルモードについて何も述べていない。 従って、アプリケーションは
148 \fBmkstemp\fP()  (や \fBmkostemp\fP())  を呼び出す前にファイルモード生成マスク (\fBumask\fP(2)  参照)
149 が適切に設定されているか確認するべきである。
150
151 \fBmktemp\fP()  のプロトタイプ宣言は、libc4, libc5, glibc1 では \fI<unistd.h>\fP に含まれる;
152 glibc2 では POSIX.1 に準拠し \fI<stdlib.h>\fP に含まれている。
153 .SH 関連項目
154 \fBmkdtemp\fP(3), \fBmktemp\fP(3), \fBtempnam\fP(3), \fBtmpfile\fP(3), \fBtmpnam\fP(3)
155 .SH この文書について
156 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
157 である。プロジェクトの説明とバグ報告に関する情報は
158 http://www.kernel.org/doc/man\-pages/ に書かれている。