OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / draft / man2 / truncate.2
1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)truncate.2  6.9 (Berkeley) 3/10/91
33 .\"
34 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
35 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
36 .\" Modified 1998-12-21 by Andries Brouwer <aeb@cwi.nl>
37 .\" Modified 2002-01-07 by Michael Kerrisk <mtk.manpages@gmail.com>
38 .\" Modified 2002-04-06 by Andries Brouwer <aeb@cwi.nl>
39 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
40 .\"
41 .\" Japanese Version Copyright (c) 1997 SUTO, Mitsuaki
42 .\"         all rights reserved.
43 .\" Translated 1997-06-26, SUTO, Mitsuaki <suto@av.crl.sony.co.jp>
44 .\" Modified 2000-03-12, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
45 .\" Updated 2001-01-09, Kentaro Shirakata <argrath@ub32.org>
46 .\" Updated 2002-04-13, Kentaro Shirakata <argrath@ub32.org>
47 .\" Updated 2002-10-21, Kentaro Shirakata <argrath@ub32.org>
48 .\" Updated 2005-09-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
49 .\" Updated 2006-07-21, Akihiro MOTOKI, LDP v2.36
50 .\"
51 .TH TRUNCATE 2 2010-10-07 "Linux" "Linux Programmer's Manual"
52 .\"O .SH NAME
53 .SH 名前
54 .\"O truncate, ftruncate \- truncate a file to a specified length
55 truncate, ftruncate \- 指定した長さにファイルを切り詰める
56 .\"O .SH SYNOPSIS
57 .SH 書式
58 .B #include <unistd.h>
59 .br
60 .B #include <sys/types.h>
61 .sp
62 .BI "int truncate(const char *" path ", off_t " length );
63 .br
64 .BI "int ftruncate(int " fd ", off_t " length );
65 .sp
66 .in -4n
67 .\"O Feature Test Macro Requirements for glibc (see
68 .\"O .BR feature_test_macros (7)):
69 glibc 向けの機能検査マクロの要件
70 .RB ( feature_test_macros (7)
71 参照):
72 .in
73 .ad l
74 .PD 0
75 .sp
76 .BR truncate ():
77 .RS 4
78 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
79 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
80 .br
81 .\"O || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
82 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
83 .RE
84 .sp
85 .BR ftruncate ():
86 .RS 4
87 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
88 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
89 .br
90 .\"O || /* Since glibc 2.3.5: */ _POSIX_C_SOURCE\ >=\ 200112L
91 || /* glibc 2.3.5 以降: */ _POSIX_C_SOURCE\ >=\ 200112L
92 .RE
93 .PD
94 .ad b
95 .\"O .SH DESCRIPTION
96 .SH 説明
97 .\"O The
98 .\"O .BR truncate ()
99 .\"O and
100 .\"O .BR ftruncate ()
101 .\"O functions cause the regular file named by
102 .\"O .I path
103 .\"O or referenced by
104 .\"O .I fd
105 .\"O to be truncated to a size of precisely
106 .\"O .I length
107 .\"O bytes.
108 .\"O If the file previously was larger than this size, the extra data is lost.
109 .BR truncate ()
110
111 .I path
112 で指定されるファイルを、
113 .BR ftruncate ()
114
115 .I fd
116 で参照されるファイルを
117 .I length
118 バイトの長さになるように延長する、もしくは切り詰める。
119 もし切り詰める前のファイルが
120 .I length
121 より長ければ、length バイトを越える部分のデータは失われる。
122 .\"O If the file previously was shorter, it is extended, and
123 .\"O the extended part reads as null bytes (\(aq\\0\(aq).
124 もし切り詰める前のファイルが
125 .I length
126 より短かければ、伸張される。
127 伸張された部分を読んだ場合は NULL バイト (\(aq\\0\(aq) の列が返される。
128 .LP
129 .\"O The file offset is not changed.
130 ファイルオフセットは変更されない。
131 .LP
132 .\"O If the size changed, then the st_ctime and st_mtime fields
133 .\"O (respectively, time of last status change and
134 .\"O time of last modification; see
135 .\"O .BR stat (2))
136 .\"O for the file are updated,
137 .\"O and the set-user-ID and set-group-ID permission bits may be cleared.
138 大きさが変更されると、ファイルの st_ctime と st_mtime フィールド
139 (それぞれ最終状態変更時刻、最終修正時刻;
140 .BR stat (2)
141 参照) が更新される。
142 また、set-user-ID と set-group-ID の許可ビットがクリアされるかもしれない。
143 .LP
144 .\"O With
145 .\"O .BR ftruncate (),
146 .\"O the file must be open for writing; with
147 .\"O .BR truncate (),
148 .\"O the file must be writable.
149 .BR ftruncate ()
150 の場合、ファイルは書き込み用に開いていなければならない。
151 .BR truncate ()
152 の場合、ファイルは書き込み可能でなければならない。
153 .\"O .SH "RETURN VALUE"
154 .SH 返り値
155 .\"O On success, zero is returned.
156 .\"O On error, \-1 is returned, and
157 .\"O .I errno
158 .\"O is set appropriately.
159 成功した場合 0 が返る。失敗した場合 \-1 が返り、
160 .I errno
161 がエラーの内容に従って設定される。
162 .\"O .SH ERRORS
163 .SH エラー
164 .\"O For
165 .\"O .BR truncate ():
166 .BR truncate ()
167 では以下のエラーコードが定義されている。
168 .TP
169 .B EACCES
170 .\"O Search permission is denied for a component of the path prefix,
171 .\"O or the named file is not writable by the user.
172 .\"O (See also
173 .\"O .BR path_resolution (7).)
174 パスで指定されているディレクトリに検索許可のないものがある
175 (訳注:x ビットが立っていない)。
176 あるいは、指定されたファイルに対する書き込み許可を持っていない。
177 .RB ( path_resolution (7)
178 も参照のこと)
179 .TP
180 .B EFAULT
181 .\"O .I Path
182 .\"O points outside the process's allocated address space.
183 .I path
184 がプロセスに割り当てられているアドレス空間外を指している。
185 .TP
186 .B EFBIG
187 .\"O The argument
188 .\"O .I length
189 .\"O is larger than the maximum file size. (XSI)
190 引き数
191 .I length
192 が最大ファイルサイズより大きい。(XSI)
193 .TP
194 .B EINTR
195 .\"O A signal was caught during execution.
196 実行中にシグナルを受けた。
197 .TP
198 .B EINVAL
199 .\"O The argument
200 .\"O .I length
201 .\"O is negative or larger than the maximum file size.
202 引き数
203 .I length
204 が負数であるか、最大ファイルサイズより大きい。
205 .TP
206 .B EIO
207 .\"O An I/O error occurred updating the inode.
208 inode の更新時に I/O エラーが発生した。
209 .TP
210 .B EINTR
211 .\"O While blocked waiting to complete,
212 .\"O the call was interrupted by a signal handler; see
213 .\"O .BR fcntl (2)
214 .\"O and
215 .\"O .BR signal (7).
216 完了待ちで停止 (block) している間に、呼び出しが
217 シグナルハンドラにより割り込まれた。
218 .BR fcntl (2)
219
220 .BR signal (7)
221 を参照。
222 .TP
223 .B EISDIR
224 .\"O The named file is a directory.
225 指定されたファイルはディレクトリである。
226 .TP
227 .B ELOOP
228 .\"O Too many symbolic links were encountered in translating the pathname.
229 パス名を解釈する際にシンボリックリンクが多すぎた。
230 .TP
231 .B ENAMETOOLONG
232 .\"O A component of a pathname exceeded 255 characters,
233 .\"O or an entire pathname exceeded 1023 characters.
234 パス名中のディレクトリ名が 255 文字を越えている、もしくはパス名全体が
235 1023 文字を越えている。
236 .TP
237 .B ENOENT
238 .\"O The named file does not exist.
239 指定された名前のファイルが存在しない。
240 .TP
241 .B ENOTDIR
242 .\"O A component of the path prefix is not a directory.
243 パス名中の項目にディレクトリではないものが入っている。
244 .TP
245 .B EPERM
246 .\" This happens for at least MSDOS and VFAT file systems
247 .\" on kernel 2.6.13
248 .\"O The underlying file system does not support extending
249 .\"O a file beyond its current size.
250 下層にあるファイルシステムでは、現在のファイル長を越えて
251 ファイルを伸長することができない。
252 .TP
253 .B EROFS
254 .\"O The named file resides on a read-only file system.
255 指定されたファイルは読み出し専用のファイルシステム中にある。
256 .TP
257 .B ETXTBSY
258 .\"O The file is a pure procedure (shared text) file that is being executed.
259 指定されたファイルは実行されているファイルである。
260 .PP
261 .\"O For
262 .\"O .BR ftruncate ()
263 .\"O the same errors apply, but instead of things that can be wrong with
264 .\"O .IR path ,
265 .\"O we now have things that can be wrong with the file descriptor,
266 .\"O .IR fd :
267 .BR ftruncate  ()
268 にも同様のエラーが適用される。
269 但し、
270 .I path
271 に関するエラーの場合は、ファイルディスクリプター
272 .I fd
273 に関するエラーとなる。
274 .TP
275 .B EBADF
276 .\"O .I fd
277 .\"O is not a valid descriptor.
278 .I fd
279 が無効なディスクリプターである。
280 .TP
281 .\"O .BR EBADF " or " EINVAL
282 .BR EBADF " または " EINVAL
283 .\"O .I fd
284 .\"O is not open for writing.
285 .I fd
286 で指定されているものが書き込みモードで開かれていない。
287 .TP
288 .B EINVAL
289 .\"O .I fd
290 .\"O does not reference a regular file.
291 .I fd
292 が通常のファイルを参照していない。
293 .\"O .SH "CONFORMING TO"
294 .SH 準拠
295 .\"O 4.4BSD, SVr4, POSIX.1-2001 (these calls first appeared in 4.2BSD).
296 4.4BSD, SVr4, POSIX.1-2001 (これらのコールは 4.2BSD で初めて登場した)。
297 .\"O .\" POSIX 1003.1-1996 has
298 .\"O .\" .BR ftruncate ().
299 .\"O .\" POSIX.1-2001 also has
300 .\"O .\" .BR truncate (),
301 .\"O .\" as an XSI extension.
302 .\"O .\" .LP
303 .\"O .\" SVr4 documents additional
304 .\"O .\" .BR truncate ()
305 .\"O .\" error conditions EMFILE, EMULTIHP, ENFILE, ENOLINK.  SVr4 documents for
306 .\"O .\" .BR ftruncate ()
307 .\"O .\" an additional EAGAIN error condition.
308 .\" POSIX 1003.1-1996 には
309 .\" .BR ftruncate ()
310 .\" がある。
311 .\" POSIX.1-2001 には
312 .\" XSI 拡張として
313 .\" .BR truncate ()
314 .\" もある。
315 .\" .LP
316 .\" SVr4 には他のエラーコードとして、
317 .\" .BR truncate ()
318 .\" には EMFILE, EMULTIHP, ENFILE, ENOLINK が、
319 .\" .BR ftruncate ()
320 .\" には EAGAIN がそれぞれ記述されている。
321 .\"O .SH NOTES
322 .SH 注意
323 .\"O The above description is for XSI-compliant systems.
324 .\"O For non-XSI-compliant systems, the POSIX standard allows
325 .\"O two behaviors for
326 .\"O .BR ftruncate ()
327 .\"O when
328 .\"O .I length
329 .\"O exceeds the file length
330 .\"O (note that
331 .\"O .BR truncate ()
332 .\"O is not specified at all in such an environment):
333 .\"O either returning an error, or extending the file.
334 上記の記述は XSI 準拠のシステムのものである。
335 XSI 非準拠のシステムの場合、POSIX 標準は
336 .BR ftruncate ()
337 に対して
338 .I length
339 がファイルの長さより長かった場合、
340 エラーを返すかファイルを伸張するかの二つの動作を許容している。
341 .BR truncate ()
342 に対しては全く規定されていない。
343 .\"O Like most UNIX implementations, Linux follows the XSI requirement
344 .\"O when dealing with native file systems.
345 .\"O However, some nonnative file systems do not permit
346 .\"O .BR truncate ()
347 .\"O and
348 .\"O .BR ftruncate ()
349 .\"O to be used to extend a file beyond its current length:
350 .\"O a notable example on Linux is VFAT.
351 ほとんどの UNIX 実装と同様、Linux はネイティブ (Linux 由来) の
352 ファイルシステムの扱いでは XSI 要求仕様にしたがっている。
353 しかしながら、いくつかの非ネイティブのファイルシステムでは、
354 .BR truncate ()
355
356 .BR ftruncate ()
357 を使って現在のファイル長を越えてファイルを伸長することができない。
358 Linux での有名な例としては VFAT がある。
359 .\"O .\" At the very least: OSF/1, Solaris 7, and FreeBSD conform, mtk, Jan 2002
360 .\"O .SH BUGS
361 .SH バグ
362 .\"O A header file bug in glibc 2.12 meant that the minimum value of
363 .\"O .\" http://sourceware.org/bugzilla/show_bug.cgi?id=12037
364 .\"O .BR _POSIX_C_SOURCE
365 .\"O required to expose the declaration of
366 .\"O .BR ftruncate ()
367 .\"O was 200809L instead of 200112L.
368 .\"O This has been fixed in later glibc versions.
369 glibc 2.12 のヘッダファイルにはバグがあり、
370 .BR ftruncate ()
371 の宣言を公開するのに必要な
372 .B _POSIX_C_SOURCE
373 の最小値が 200112L ではなく 200809L となっていた。
374 このバグは、これ以降のバージョンの glibc では修正されている。
375 .\"O .SH "SEE ALSO"
376 .SH 関連項目
377 .BR open (2),
378 .BR stat (2),
379 .BR path_resolution (7)