1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
32 .\" @(#)truncate.2 6.9 (Berkeley) 3/10/91
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>
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
51 .TH TRUNCATE 2 2010-10-07 "Linux" "Linux Programmer's Manual"
54 .\"O truncate, ftruncate \- truncate a file to a specified length
55 truncate, ftruncate \- 指定した長さにファイルを切り詰める
58 .B #include <unistd.h>
60 .B #include <sys/types.h>
62 .BI "int truncate(const char *" path ", off_t " length );
64 .BI "int ftruncate(int " fd ", off_t " length );
67 .\"O Feature Test Macro Requirements for glibc (see
68 .\"O .BR feature_test_macros (7)):
70 .RB ( feature_test_macros (7)
78 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
79 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
81 .\"O || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
82 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
87 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
88 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
90 .\"O || /* Since glibc 2.3.5: */ _POSIX_C_SOURCE\ >=\ 200112L
91 || /* glibc 2.3.5 以降: */ _POSIX_C_SOURCE\ >=\ 200112L
100 .\"O .BR ftruncate ()
101 .\"O functions cause the regular file named by
103 .\"O or referenced by
105 .\"O to be truncated to a size of precisely
108 .\"O If the file previously was larger than this size, the extra data is lost.
118 バイトの長さになるように延長する、もしくは切り詰める。
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).
127 伸張された部分を読んだ場合は NULL バイト (\(aq\\0\(aq) の列が返される。
129 .\"O The file offset is not changed.
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
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 (それぞれ最終状態変更時刻、最終修正時刻;
142 また、set-user-ID と set-group-ID の許可ビットがクリアされるかもしれない。
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.
150 の場合、ファイルは書き込み用に開いていなければならない。
152 の場合、ファイルは書き込み可能でなければならない。
153 .\"O .SH "RETURN VALUE"
155 .\"O On success, zero is returned.
156 .\"O On error, \-1 is returned, and
158 .\"O is set appropriately.
159 成功した場合 0 が返る。失敗した場合 \-1 が返り、
165 .\"O .BR truncate ():
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.
173 .\"O .BR path_resolution (7).)
174 パスで指定されているディレクトリに検索許可のないものがある
176 あるいは、指定されたファイルに対する書き込み許可を持っていない。
177 .RB ( path_resolution (7)
182 .\"O points outside the process's allocated address space.
184 がプロセスに割り当てられているアドレス空間外を指している。
189 .\"O is larger than the maximum file size. (XSI)
192 が最大ファイルサイズより大きい。(XSI)
195 .\"O A signal was caught during execution.
201 .\"O is negative or larger than the maximum file size.
204 が負数であるか、最大ファイルサイズより大きい。
207 .\"O An I/O error occurred updating the inode.
208 inode の更新時に I/O エラーが発生した。
211 .\"O While blocked waiting to complete,
212 .\"O the call was interrupted by a signal handler; see
216 完了待ちで停止 (block) している間に、呼び出しが
224 .\"O The named file is a directory.
228 .\"O Too many symbolic links were encountered in translating the pathname.
229 パス名を解釈する際にシンボリックリンクが多すぎた。
232 .\"O A component of a pathname exceeded 255 characters,
233 .\"O or an entire pathname exceeded 1023 characters.
234 パス名中のディレクトリ名が 255 文字を越えている、もしくはパス名全体が
238 .\"O The named file does not exist.
242 .\"O A component of the path prefix is not a directory.
243 パス名中の項目にディレクトリではないものが入っている。
246 .\" This happens for at least MSDOS and VFAT file systems
248 .\"O The underlying file system does not support extending
249 .\"O a file beyond its current size.
250 下層にあるファイルシステムでは、現在のファイル長を越えて
254 .\"O The named file resides on a read-only file system.
255 指定されたファイルは読み出し専用のファイルシステム中にある。
258 .\"O The file is a pure procedure (shared text) file that is being executed.
259 指定されたファイルは実行されているファイルである。
262 .\"O .BR ftruncate ()
263 .\"O the same errors apply, but instead of things that can be wrong with
265 .\"O we now have things that can be wrong with the file descriptor,
271 に関するエラーの場合は、ファイルディスクリプター
277 .\"O is not a valid descriptor.
281 .\"O .BR EBADF " or " EINVAL
282 .BR EBADF " または " EINVAL
284 .\"O is not open for writing.
286 で指定されているものが書き込みモードで開かれていない。
290 .\"O does not reference a regular file.
293 .\"O .SH "CONFORMING TO"
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.
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 には
316 .\" SVr4 には他のエラーコードとして、
318 .\" には EMFILE, EMULTIHP, ENFILE, ENOLINK が、
320 .\" には EAGAIN がそれぞれ記述されている。
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 ()
329 .\"O exceeds the file length
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 標準は
340 エラーを返すかファイルを伸張するかの二つの動作を許容している。
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
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 しかしながら、いくつかの非ネイティブのファイルシステムでは、
357 を使って現在のファイル長を越えてファイルを伸長することができない。
358 Linux での有名な例としては VFAT がある。
359 .\"O .\" At the very least: OSF/1, Solaris 7, and FreeBSD conform, mtk, Jan 2002
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 のヘッダファイルにはバグがあり、
373 の最小値が 200112L ではなく 200809L となっていた。
374 このバグは、これ以降のバージョンの glibc では修正されている。
379 .BR path_resolution (7)