OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[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 .\"*******************************************************************
34 .\"
35 .\" This file was generated with po4a. Translate the source file.
36 .\"
37 .\"*******************************************************************
38 .TH MKSTEMP 3 2010\-09\-26 GNU "Linux Programmer's Manual"
39 .SH 名前
40 mkstemp, mkostemp \- 他と重ならない名前を持つ一時ファイルを作成する
41 .SH 書式
42 .nf
43 \fB#include <stdlib.h>\fP
44 .sp
45 \fBint mkstemp(char *\fP\fItemplate\fP\fB);\fP
46 .sp
47 \fBint mkostemp(char *\fP\fItemplate\fP\fB, int \fP\fIflags\fP\fB);\fP
48 .sp
49 \fBint mkstemps(char *\fP\fItemplate\fP\fB, int \fP\fIsuffixlen\fP\fB);\fP
50 .sp
51 \fBint mkostemps(char *\fP\fItemplate\fP\fB, int \fP\fIsuffixlen\fP\fB, int \fP\fIflags\fP\fB);\fP
52 .fi
53 .sp
54 .in -4n
55 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
56 .in
57 .sp
58 \fBmkstemp\fP():
59 .ad l
60 .RS 4
61 .PD 0
62 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
63 .br
64 || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200112L
65 .PD
66 .RE
67 .ad b
68 .PP
69 \fBmkostemp\fP(): _GNU_SOURCE
70 .br
71 \fBmkstemps\fP(): _BSD_SOURCE || _SVID_SOURCE
72 .br
73 \fBmkostemps\fP(): _GNU_SOURCE
74 .SH 説明
75 関数 \fBmkstemp\fP()  は引数 \fItemplate\fP から他と重ならない一時ファイル名を生成し、 そのファイルの作成とオープンを行い、
76 そのファイルに対するオープン済みのファイルディスクリプタを返す。
77
78 引数 \fItemplate\fP で指示する文字列の後ろの 6 文字は XXXXXX である必要がある。
79 この部分がファイル名を他と重ならないようにする文字で置き換えられる。 \fItemplate\fP は書き換えられるため、文字列定数ではなく文字配列として
80 宣言するようにしなければならない。
81
82 ファイルは許可モード 0600 で作成され、所有者のみが読み書き可能である (glibc バージョン 2.06 以前では、ファイルは許可モード 0666
83 で作成され、 全てのユーザが読み書き可能であった)。 返されるファイルディスクリプタで、このファイルへの読み書き両方のアクセスが 可能である。
84 呼び出し者がそのファイルを作成するプロセスであることを保証するために、 ファイルは \fBopen\fP(2)  の \fBO_EXCL\fP
85 フラグ付きでオープンされる。
86
87 \fBmkostemp\fP() 関数は \fBmkstemp\fP() と同様だが、\fBopen\fP(2) に渡される
88 フラグ O_APPEND\fB,\fP \fBO_SYNC\fP など) を \fIflags\fP で指定できる点が異なる
89
90 \fBmkstemps\fP() 関数は \fBmkstemp\fP() と同様だが、 \fItemplate\fP 内の文字列に長さ
91 が \fIsuffixlen\fP 文字の接尾辞 (suffix) が含まれる点が異なる。
92 したがって、 \fItemplate\fP は \fIprefixXXXXXXsuffix\fP の形式となる。
93 文字列 XXXXXX の部分は \fBmkstemp\fP() により更新される。
94
95 \fBmkostemps\fP() と \fBmkstemps\fP() の関係は、
96 \fBmkostemp\fP() と \fBmkstemp\fP() の関係と同じである。
97 .SH 返り値
98 成功すると、これらの関数は一時ファイルのファイルディスクリプタを返す。 エラーの場合は、\-1 を返し、 \fIerrno\fP を適切に設定する。
99 .SH エラー
100 .TP 
101 \fBEEXIST\fP
102 すでに同じ名前を持つファイルが存在した。 \fItemplate\fP の内容は不定である。
103 .TP 
104 \fBEINVAL\fP
105 \fBmkstemp\fP() と \fBmkostemp\fP() の場合:
106 \fItemplate\fP の最後の 6 文字が XXXXXX でなかった。
107 この場合、\fItemplate\fP は変更されない。
108 .sp
109 \fBmkstemps\fP() と \fBmkostemps\fP() の場合:
110 \fItemplate\fP の長さが \fI(6 + suffixlen)\fP 文字より短い、または
111 \fItemplate\fP の接尾辞の直前の 6 文字が XXXXXX ではなかった。
112 .PP
113 これらの関数は \fBopen\fP(2) に書かれているエラーのいずれかで失敗することもある。
114 .SH バージョン
115 \fBmkostemp\fP() は glibc 2.7 以降で利用できる。
116 \fBmkstemps\fP() と \fBmkostemps\fP() は glibc 2.11 以降で利用できる。
117 .SH 準拠
118 \fBmkstemp\fP(): 4.3BSD, POSIX.1\-2001.
119
120 .\" mkstemps() appears to be at least on the BSDs, Mac OS X, Solaris,
121 .\" and Tru64.
122 \fBmkstemps\fP(): 標準化されていないが、他のいくつかのシステムにも存在する。
123
124 \fBmkostemp\fP() と \fBmkostemps\fP(): glibc による拡張。
125 .SH 注意
126 許可モード 0666 でファイルを作成するという古い動作は、 セキュリティ上のリスク
127 になる場合がある。 特に他の UNIX では許可モードとして 0600 を使うため、
128 プログラムを移植する際、この細かな違いを見落とす可能性があるからだ。
129
130 より一般的には、 \fBmkstemp\fP()  の POSIX 規定ではファイルモードについて何も述べていない。 従って、アプリケーションは
131 \fBmkstemp\fP()  (や \fBmkostemp\fP())  を呼び出す前にファイルモード生成マスク (\fBumask\fP(2)  参照)
132 が適切に設定されているか確認するべきである。
133
134 \fBmktemp\fP()  のプロトタイプ宣言は、libc4, libc5, glibc1 では \fI<unistd.h>\fP に含まれる;
135 glibc2 では POSIX.1 に準拠し \fI<stdlib.h>\fP に含まれている。
136 .SH 関連項目
137 \fBmkdtemp\fP(3), \fBmktemp\fP(3), \fBtempnam\fP(3), \fBtmpfile\fP(3), \fBtmpnam\fP(3)