OSDN Git Service

(split) LDP: Update release pages based on LDP 3.54 release
[linuxjm/LDP_man-pages.git] / release / man2 / truncate.2
1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\"    must display the following acknowledgement:
15 .\"     This product includes software developed by the University of
16 .\"     California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\"    may be used to endorse or promote products derived from this software
19 .\"    without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" SUCH DAMAGE.
32 .\" %%%LICENSE_END
33 .\"
34 .\"     @(#)truncate.2  6.9 (Berkeley) 3/10/91
35 .\"
36 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
37 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
38 .\" Modified 1998-12-21 by Andries Brouwer <aeb@cwi.nl>
39 .\" Modified 2002-01-07 by Michael Kerrisk <mtk.manpages@gmail.com>
40 .\" Modified 2002-04-06 by Andries Brouwer <aeb@cwi.nl>
41 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
42 .\"
43 .\"*******************************************************************
44 .\"
45 .\" This file was generated with po4a. Translate the source file.
46 .\"
47 .\"*******************************************************************
48 .\"
49 .\" Japanese Version Copyright (c) 1997 SUTO, Mitsuaki
50 .\"         all rights reserved.
51 .\" Translated 1997-06-26, SUTO, Mitsuaki <suto@av.crl.sony.co.jp>
52 .\" Modified 2000-03-12, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
53 .\" Updated 2001-01-09, Kentaro Shirakata <argrath@ub32.org>
54 .\" Updated 2002-04-13, Kentaro Shirakata <argrath@ub32.org>
55 .\" Updated 2002-10-21, Kentaro Shirakata <argrath@ub32.org>
56 .\" Updated 2005-09-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
57 .\" Updated 2006-07-21, Akihiro MOTOKI, LDP v2.36
58 .\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
59 .\" Updated 2013-05-01, Akihiro MOTOKI <amotoki@gmail.com>
60 .\"
61 .TH TRUNCATE 2 2013\-04\-01 Linux "Linux Programmer's Manual"
62 .SH 名前
63 truncate, ftruncate \- 指定した長さにファイルを切り詰める
64 .SH 書式
65 \fB#include <unistd.h>\fP
66 .br
67 \fB#include <sys/types.h>\fP
68 .sp
69 \fBint truncate(const char *\fP\fIpath\fP\fB, off_t \fP\fIlength\fP\fB);\fP
70 .br
71 \fBint ftruncate(int \fP\fIfd\fP\fB, off_t \fP\fIlength\fP\fB);\fP
72 .sp
73 .in -4n
74 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
75 .in
76 .ad l
77 .PD 0
78 .sp
79 \fBtruncate\fP():
80 .RS 4
81 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
82 .br
83 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
84 .RE
85 .sp
86 \fBftruncate\fP():
87 .RS 4
88 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
89 .br
90 || /* glibc 2.3.5 以降: */ _POSIX_C_SOURCE\ >=\ 200112L
91 .RE
92 .PD
93 .ad b
94 .SH 説明
95 \fBtruncate\fP()  は \fIpath\fP で指定されるファイルを、 \fBftruncate\fP()  は \fIfd\fP で参照されるファイルを
96 \fIlength\fP バイトの長さになるように延長する、もしくは切り詰める。
97 .LP
98 もし切り詰める前のファイルが \fIlength\fP より長ければ、length バイトを越える部分のデータは失われる。 もし切り詰める前のファイルが
99 \fIlength\fP より短かければ、伸張される。 伸張された部分を読んだ場合は NULL バイト (\(aq\e0\(aq) の列が返される。
100 .LP
101 ファイルオフセットは変更されない。
102 .LP
103 大きさが変更されると、ファイルの st_ctime と st_mtime フィールド (それぞれ最終状態変更時刻、最終修正時刻; \fBstat\fP(2)
104 参照) が更新される。 また、set\-user\-ID と set\-group\-ID の許可ビットがクリアされるかもしれない。
105 .LP
106 \fBftruncate\fP()  の場合、ファイルは書き込み用に開いていなければならない。 \fBtruncate\fP()
107 の場合、ファイルは書き込み可能でなければならない。
108 .SH 返り値
109 成功した場合は 0 が返される。エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。
110 .SH エラー
111 \fBtruncate\fP()  では以下のエラーコードが定義されている。
112 .TP 
113 \fBEACCES\fP
114 パスで指定されているディレクトリに検索許可のないものがある (訳注:x ビットが立っていない)。
115 あるいは、指定されたファイルに対する書き込み許可を持っていない。 (\fBpath_resolution\fP(7)  も参照のこと)
116 .TP 
117 \fBEFAULT\fP
118 \fIpath\fP がプロセスに割り当てられているアドレス空間外を指している。
119 .TP 
120 \fBEFBIG\fP
121 引き数 \fIlength\fP が最大ファイルサイズより大きい。(XSI)
122 .TP 
123 \fBEINTR\fP
124 完了待ちで停止 (block) している間に、呼び出しが シグナルハンドラにより割り込まれた。 \fBfcntl\fP(2)  と \fBsignal\fP(7)
125 を参照。
126 .TP 
127 \fBEINVAL\fP
128 引き数 \fIlength\fP が負数であるか、最大ファイルサイズより大きい。
129 .TP 
130 \fBEIO\fP
131 inode の更新時に I/O エラーが発生した。
132 .TP 
133 \fBEISDIR\fP
134 指定されたファイルはディレクトリである。
135 .TP 
136 \fBELOOP\fP
137 パス名を解釈する際にシンボリックリンクが多すぎた。
138 .TP 
139 \fBENAMETOOLONG\fP
140 パス名中のディレクトリ名が 255 文字を越えている、もしくはパス名全体が 1023 文字を越えている。
141 .TP 
142 \fBENOENT\fP
143 指定された名前のファイルが存在しない。
144 .TP 
145 \fBENOTDIR\fP
146 パス名の構成要素がディレクトリではない。
147 .TP 
148 \fBEPERM\fP
149 .\" This happens for at least MSDOS and VFAT filesystems
150 .\" on kernel 2.6.13
151 The underlying filesystem does not support extending a file beyond its
152 current size.
153 .TP 
154 \fBEROFS\fP
155 The named file resides on a read\-only filesystem.
156 .TP 
157 \fBETXTBSY\fP
158 指定されたファイルは実行されているファイルである。
159 .PP
160 \fBftruncate\fP()  にも同様のエラーが適用される。 但し、 \fIpath\fP に関するエラーの場合は、ファイルディスクリプター \fIfd\fP
161 に関するエラーとなる。
162 .TP 
163 \fBEBADF\fP
164 \fIfd\fP が無効なディスクリプターである。
165 .TP 
166 \fBEBADF\fP または \fBEINVAL\fP
167 \fIfd\fP で指定されているものが書き込みモードで開かれていない。
168 .TP 
169 \fBEINVAL\fP
170 \fIfd\fP が通常のファイルを参照していない。
171 .SH 準拠
172 .\" POSIX.1-1996 has
173 .\" .BR ftruncate ().
174 .\" POSIX.1-2001 also has
175 .\" .BR truncate (),
176 .\" as an XSI extension.
177 .\" .LP
178 .\" SVr4 documents additional
179 .\" .BR truncate ()
180 .\" error conditions EMFILE, EMULTIHP, ENFILE, ENOLINK.  SVr4 documents for
181 .\" .BR ftruncate ()
182 .\" an additional EAGAIN error condition.
183 4.4BSD, SVr4, POSIX.1\-2001 (これらのコールは 4.2BSD で初めて登場した)。
184 .SH 注意
185 .\" At the very least: OSF/1, Solaris 7, and FreeBSD conform, mtk, Jan 2002
186 The details in DESCRIPTION are for XSI\-compliant systems.  For
187 non\-XSI\-compliant systems, the POSIX standard allows two behaviors for
188 \fBftruncate\fP()  when \fIlength\fP exceeds the file length (note that
189 \fBtruncate\fP()  is not specified at all in such an environment): either
190 returning an error, or extending the file.  Like most UNIX implementations,
191 Linux follows the XSI requirement when dealing with native filesystems.
192 However, some nonnative filesystems do not permit \fBtruncate\fP()  and
193 \fBftruncate\fP()  to be used to extend a file beyond its current length: a
194 notable example on Linux is VFAT.
195
196 元々の Linux の \fBtruncate\fP() と \fBftruncate\fP() システムコールは
197 大きなファイルオフセットを扱えるように設計されていなかった。
198 その結果、大きなファイルファイルを扱うことができる \fBtruncate64\fP() と \fBftruncate64\fP()
199 システムコールが Linux 2.4 で追加された。
200 ただし、glibc を使ったアプリケーションではこれらの詳細は気にする必要はない。
201 glibc のラッパー関数は新しいシステムコールが利用できる場合にはそれらを利用する
202 ようになっているからである。
203
204 いくつかの 32 ビットアーキテクチャでは、これらのシステムコールの呼び出し時のシグネチャーが違っています。理由は \fBsyscall\fP(2)
205 で説明されている通りです。
206 .SH バグ
207 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=12037
208 glibc 2.12 のヘッダファイルにはバグがあり、 \fBftruncate\fP()  の宣言を公開するのに必要な \fB_POSIX_C_SOURCE\fP
209 の最小値が 200112L ではなく 200809L となっていた。 このバグは、これ以降のバージョンの glibc では修正されている。
210 .SH 関連項目
211 \fBopen\fP(2), \fBstat\fP(2), \fBpath_resolution\fP(7)
212 .SH この文書について
213 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
214 である。プロジェクトの説明とバグ報告に関する情報は
215 http://www.kernel.org/doc/man\-pages/ に書かれている。