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"
53 truncate, ftruncate \- 指定した長さにファイルを切り詰める
55 .B #include <unistd.h>
57 .B #include <sys/types.h>
59 .BI "int truncate(const char *" path ", off_t " length );
61 .BI "int ftruncate(int " fd ", off_t " length );
65 .RB ( feature_test_macros (7)
73 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
74 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
76 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
81 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
82 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
84 || /* glibc 2.3.5 以降: */ _POSIX_C_SOURCE\ >=\ 200112L
98 バイトの長さになるように延長する、もしくは切り詰める。
101 より長ければ、length バイトを越える部分のデータは失われる。
105 伸張された部分を読んだ場合は NULL バイト (\(aq\\0\(aq) の列が返される。
109 大きさが変更されると、ファイルの st_ctime と st_mtime フィールド
110 (それぞれ最終状態変更時刻、最終修正時刻;
113 また、set-user-ID と set-group-ID の許可ビットがクリアされるかもしれない。
116 の場合、ファイルは書き込み用に開いていなければならない。
118 の場合、ファイルは書き込み可能でなければならない。
120 成功した場合 0 が返る。失敗した場合 \-1 が返り、
128 パスで指定されているディレクトリに検索許可のないものがある
130 あるいは、指定されたファイルに対する書き込み許可を持っていない。
131 .RB ( path_resolution (7)
136 がプロセスに割り当てられているアドレス空間外を指している。
141 が最大ファイルサイズより大きい。(XSI)
149 が負数であるか、最大ファイルサイズより大きい。
152 inode の更新時に I/O エラーが発生した。
155 完了待ちで停止 (block) している間に、呼び出しが
166 パス名を解釈する際にシンボリックリンクが多すぎた。
169 パス名中のディレクトリ名が 255 文字を越えている、もしくはパス名全体が
176 パス名中の項目にディレクトリではないものが入っている。
179 .\" This happens for at least MSDOS and VFAT file systems
181 下層にあるファイルシステムでは、現在のファイル長を越えて
185 指定されたファイルは読み出し専用のファイルシステム中にある。
188 指定されたファイルは実行されているファイルである。
194 に関するエラーの場合は、ファイルディスクリプター
202 .BR EBADF " または " EINVAL
204 で指定されているものが書き込みモードで開かれていない。
210 4.4BSD, SVr4, POSIX.1-2001 (これらのコールは 4.2BSD で初めて登場した)。
211 .\" POSIX 1003.1-1996 には
219 .\" SVr4 には他のエラーコードとして、
221 .\" には EMFILE, EMULTIHP, ENFILE, ENOLINK が、
223 .\" には EAGAIN がそれぞれ記述されている。
225 上記の記述は XSI 準拠のシステムのものである。
226 XSI 非準拠のシステムの場合、POSIX 標準は
231 エラーを返すかファイルを伸張するかの二つの動作を許容している。
234 ほとんどの UNIX 実装と同様、Linux はネイティブ (Linux 由来) の
235 ファイルシステムの扱いでは XSI 要求仕様にしたがっている。
236 しかしながら、いくつかの非ネイティブのファイルシステムでは、
240 を使って現在のファイル長を越えてファイルを伸長することができない。
241 Linux での有名な例としては VFAT がある。
243 glibc 2.12 のヘッダファイルにはバグがあり、
247 の最小値が 200112L ではなく 200809L となっていた。
248 このバグは、これ以降のバージョンの glibc では修正されている。
252 .BR path_resolution (7)