OSDN Git Service

eda8fce0bc7af8681f77fe2a816bffe4e912527d
[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 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .\" References consulted:
25 .\"     Linux libc source code
26 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\"     386BSD man pages
28 .\" Modified Sat Jul 24 18:48:48 1993 by Rik Faith (faith@cs.unc.edu)
29 .\" Modified 980310, aeb
30 .\" Modified 990328, aeb
31 .\" 2008-06-19, mtk, Added mkostemp(); various other changes
32 .\"
33 .\" Japanese Version Copyright (c) 1997 Kazuyuki Tanisako
34 .\"         all rights reserved.
35 .\" Translated 1997-05-17, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
36 .\" Modified 1997-05-27, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
37 .\" Modified 1998-02-05, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
38 .\" Modified 1998-09-27, Kazuyuki Tanisako <tanisako@osa.dec-j.co.jp>
39 .\" Modified 1999-04-10, Kazuyuki Tanisako <tanisako@osa.dec.com>
40 .\" Updated 2001-01-17, Kentaro Shirakata <argrath@ub32.org>
41 .\" Updated 2005-02-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
42 .\" Updated 2008-08-10, Akihiro MOTOKI, LDP v3.05
43 .\"
44 .\"WORD:        temporary file  一時ファイル
45 .\"WORD:        read/write      リード/ライト
46 .\"WORD:        permissions     許可
47 .\"
48 .TH MKSTEMP 3  2008-06-19 "GNU" "Linux Programmer's Manual"
49 .SH 名前
50 mkstemp, mkostemp \- 他と重ならない名前を持つ一時ファイルを作成する
51 .SH 書式
52 .nf
53 .B #include <stdlib.h>
54 .sp
55 .BI "int mkstemp(char *" template );
56 .sp
57 .BI "int mkostemp (char *" template ", int " flags );
58 .fi
59 .sp
60 .in -4n
61 glibc 向けの機能検査マクロの要件
62 .RB ( feature_test_macros (7)
63 参照):
64 .in
65 .sp
66 .BR mkstemp ():
67 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500
68 .br
69 .BR mkostemp ():
70 _GNU_SOURCE
71 \"O .SH DESCRIPTION
72 .SH 説明
73 関数
74 .BR mkstemp ()
75 は引数
76 .I template
77 から他と重ならない一時ファイル名を生成し、
78 そのファイルの作成とオープンを行い、
79 そのファイルに対するオープン済みのファイルディスクリプタを返す。
80
81 引数
82 .I template
83 で指示する文字列の後ろの 6 文字は XXXXXX である必要がある。
84 この部分がファイル名を他と重ならないようにする文字で置き換えられる。
85 .I template
86 は書き換えられるため、文字列定数ではなく文字配列として
87 宣言するようにしなければならない。
88
89 ファイルは許可モード 0600 で作成され、所有者のみが読み書き可能である
90 (glibc バージョン 2.06 以前では、ファイルは許可モード 0666 で作成され、
91 全てのユーザが読み書き可能であった)。
92 返されるファイルディスクリプタで、このファイルへの読み書き両方のアクセスが
93 可能である。
94 呼び出し者がそのファイルを作成するプロセスであることを保証するために、
95 ファイルは
96 .BR open (2)
97
98 .B O_EXCL
99 フラグ付きでオープンされる。
100
101 .BR mkostemp ()
102
103 .BR mkstemp ()
104 と同様だが、
105 .BR open (2)
106 に渡されるフラグ
107 .RB O_APPEND ,
108 .B O_SYNC
109 など) を
110 .I flags
111 で指定できる点が異なる
112 .SH 返り値
113 成功すると、これらの関数は一時ファイルのファイルディスクリプタを返す。
114 エラーの場合は、\-1 を返し、
115 .I errno
116 を適切に設定する。
117 .SH エラー
118 .TP
119 .B EEXIST
120 すでに同じ名前を持つファイルが存在した。
121 \fItemplate\fP の内容は不定である。
122 .TP
123 .B EINVAL
124 引数 \fItemplate\fP で指示された文字配列の後ろの 6 文字が XXXXXX でない。
125 \fItemplate\fP の内容は変化しない。
126 .PP
127 これらの関数は
128 .BR open (2)
129 に書かわれているエラーのいずれかで失敗することもある。
130 .SH バージョン
131 .BR mkostemp ()
132 は glibc 2.7 以降で利用可能である。
133 .SH 準拠
134 .BR mkstemp ():
135 4.3BSD, POSIX.1-2001.
136 .BR mkostemp ():
137 glibc による拡張。
138 .SH 注意
139 許可モード 0666 でファイルを作成するという古い動作は、
140 セキュリティ上のリスクになる場合がある。
141 特に他の Unix では許可モードとして 0600 を使うため、
142 プログラムを移植する際、この細かな違いを見落とす可能性が
143 あるからだ。
144
145 より一般的には、
146 .BR mkstemp ()
147 の POSIX 規定ではファイルモードについて何も述べていない。
148 従って、アプリケーションは
149 .BR mkstemp ()
150 (や
151 .BR mkostemp ())
152 を呼び出す前にファイルモード生成マスク
153 .RB ( umask (2)
154 参照) が適切に設定されているか確認するべきである。
155
156 .BR mktemp ()
157 のプロトタイプ宣言は、libc4, libc5, glibc1 では
158 .I <unistd.h>
159 に含まれる; glibc2 では POSIX.1 に準拠し
160 .I <stdlib.h>
161 に含まれている。
162 .SH 関連項目
163 .BR mkdtemp (3),
164 .BR mktemp (3),
165 .BR tempnam (3),
166 .BR tmpfile (3),
167 .BR tmpnam (3)