OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[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 2009-02-28 "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 .sp
75 .BR truncate ():
76 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
77 .br
78 .BR ftruncate ():
79 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _POSIX_C_SOURCE\ >=\ 200112L
80 .ad b
81 .\"O .SH DESCRIPTION
82 .SH ÀâÌÀ
83 .\"O The
84 .\"O .BR truncate ()
85 .\"O and
86 .\"O .BR ftruncate ()
87 .\"O functions cause the regular file named by
88 .\"O .I path
89 .\"O or referenced by
90 .\"O .I fd
91 .\"O to be truncated to a size of precisely
92 .\"O .I length
93 .\"O bytes.
94 .\"O If the file previously was larger than this size, the extra data is lost.
95 .BR truncate ()
96 ¤Ï
97 .I path
98 ¤Ç»ØÄꤵ¤ì¤ë¥Õ¥¡¥¤¥ë¤ò¡¢
99 .BR ftruncate ()
100 ¤Ï
101 .I fd
102 ¤Ç»²¾È¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¤ò
103 .I length
104 ¥Ð¥¤¥È¤ÎŤµ¤Ë¤Ê¤ë¤è¤¦¤Ë±äŤ¹¤ë¡¢¤â¤·¤¯¤ÏÀÚ¤êµÍ¤á¤ë¡£
105 ¤â¤·ÀÚ¤êµÍ¤á¤ëÁ°¤Î¥Õ¥¡¥¤¥ë¤¬
106 .I length
107 ¤è¤êŤ±¤ì¤Ð¡¢length ¥Ð¥¤¥È¤ò±Û¤¨¤ëÉôʬ¤Î¥Ç¡¼¥¿¤Ï¼º¤ï¤ì¤ë¡£
108 .\"O If the file previously was shorter, it is extended, and
109 .\"O the extended part reads as null bytes (\(aq\\0\(aq).
110 ¤â¤·ÀÚ¤êµÍ¤á¤ëÁ°¤Î¥Õ¥¡¥¤¥ë¤¬
111 .I length
112 ¤è¤êû¤«¤±¤ì¤Ð¡¢¿­Ä¥¤µ¤ì¤ë¡£
113 ¿­Ä¥¤µ¤ì¤¿Éôʬ¤òÆɤó¤À¾ì¹ç¤Ï NULL ¥Ð¥¤¥È (\(aq\\0\(aq) ¤ÎÎó¤¬ÊÖ¤µ¤ì¤ë¡£
114 .LP
115 .\"O The file offset is not changed.
116 ¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
117 .LP
118 .\"O If the size changed, then the st_ctime and st_mtime fields
119 .\"O (respectively, time of last status change and
120 .\"O time of last modification; see
121 .\"O .BR stat (2))
122 .\"O for the file are updated,
123 .\"O and the set-user-ID and set-group-ID permission bits may be cleared.
124 Â礭¤µ¤¬Êѹ¹¤µ¤ì¤ë¤È¡¢¥Õ¥¡¥¤¥ë¤Î st_ctime ¤È st_mtime ¥Õ¥£¡¼¥ë¥É
125 (¤½¤ì¤¾¤ìºÇ½ª¾õÂÖÊѹ¹»þ¹ï¡¢ºÇ½ª½¤Àµ»þ¹ï;
126 .BR stat (2)
127 »²¾È) ¤¬¹¹¿·¤µ¤ì¤ë¡£
128 ¤Þ¤¿¡¢set-user-ID ¤È set-group-ID ¤Îµö²Ä¥Ó¥Ã¥È¤¬¥¯¥ê¥¢¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
129 .LP
130 .\"O With
131 .\"O .BR ftruncate (),
132 .\"O the file must be open for writing; with
133 .\"O .BR truncate (),
134 .\"O the file must be writable.
135 .BR ftruncate ()
136 ¤Î¾ì¹ç¡¢¥Õ¥¡¥¤¥ë¤Ï½ñ¤­¹þ¤ßÍѤ˳«¤¤¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
137 .BR truncate ()
138 ¤Î¾ì¹ç¡¢¥Õ¥¡¥¤¥ë¤Ï½ñ¤­¹þ¤ß²Äǽ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
139 .\"O .SH "RETURN VALUE"
140 .SH ÊÖ¤êÃÍ
141 .\"O On success, zero is returned.
142 .\"O On error, \-1 is returned, and
143 .\"O .I errno
144 .\"O is set appropriately.
145 À®¸ù¤·¤¿¾ì¹ç 0 ¤¬Ê֤롣¼ºÇÔ¤·¤¿¾ì¹ç \-1 ¤¬Ê֤ꡢ
146 .I errno
147 ¤¬¥¨¥é¡¼¤ÎÆâÍƤ˽¾¤Ã¤ÆÀßÄꤵ¤ì¤ë¡£
148 .\"O .SH ERRORS
149 .SH ¥¨¥é¡¼
150 .\"O For
151 .\"O .BR truncate ():
152 .BR truncate ()
153 ¤Ç¤Ï°Ê²¼¤Î¥¨¥é¡¼¥³¡¼¥É¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
154 .TP
155 .B EACCES
156 .\"O Search permission is denied for a component of the path prefix,
157 .\"O or the named file is not writable by the user.
158 .\"O (See also
159 .\"O .BR path_resolution (7).)
160 ¥Ñ¥¹¤Ç»ØÄꤵ¤ì¤Æ¤¤¤ë¥Ç¥£¥ì¥¯¥È¥ê¤Ë¸¡º÷µö²Ä¤Î¤Ê¤¤¤â¤Î¤¬¤¢¤ë
161 (ÌõÃí:x ¥Ó¥Ã¥È¤¬Î©¤Ã¤Æ¤¤¤Ê¤¤)¡£
162 ¤¢¤ë¤¤¤Ï¡¢»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤ËÂФ¹¤ë½ñ¤­¹þ¤ßµö²Ä¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£
163 .RB ( path_resolution (7)
164 ¤â»²¾È¤Î¤³¤È)
165 .TP
166 .B EFAULT
167 .\"O .I Path
168 .\"O points outside the process's allocated address space.
169 .I path
170 ¤¬¥×¥í¥»¥¹¤Ë³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤ë¥¢¥É¥ì¥¹¶õ´Ö³°¤ò»Ø¤·¤Æ¤¤¤ë¡£
171 .TP
172 .B EFBIG
173 .\"O The argument
174 .\"O .I length
175 .\"O is larger than the maximum file size. (XSI)
176 °ú¤­¿ô
177 .I length
178 ¤¬ºÇÂç¥Õ¥¡¥¤¥ë¥µ¥¤¥º¤è¤êÂ礭¤¤¡£(XSI)
179 .TP
180 .B EINTR
181 .\"O A signal was caught during execution.
182 ¼Â¹ÔÃæ¤Ë¥·¥°¥Ê¥ë¤ò¼õ¤±¤¿¡£
183 .TP
184 .B EINVAL
185 .\"O The argument
186 .\"O .I length
187 .\"O is negative or larger than the maximum file size.
188 °ú¤­¿ô
189 .I length
190 ¤¬Éé¿ô¤Ç¤¢¤ë¤«¡¢ºÇÂç¥Õ¥¡¥¤¥ë¥µ¥¤¥º¤è¤êÂ礭¤¤¡£
191 .TP
192 .B EIO
193 .\"O An I/O error occurred updating the inode.
194 inode ¤Î¹¹¿·»þ¤Ë I/O ¥¨¥é¡¼¤¬È¯À¸¤·¤¿¡£
195 .TP
196 .B EINTR
197 .\"O While blocked waiting to complete,
198 .\"O the call was interrupted by a signal handler; see
199 .\"O .BR fcntl (2)
200 .\"O and
201 .\"O .BR signal (7).
202 ´°Î»ÂÔ¤Á¤ÇÄä»ß (block) ¤·¤Æ¤¤¤ë´Ö¤Ë¡¢¸Æ¤Ó½Ð¤·¤¬
203 ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿¡£
204 .BR fcntl (2)
205 ¤È
206 .BR signal (7)
207 ¤ò»²¾È¡£
208 .TP
209 .B EISDIR
210 .\"O The named file is a directory.
211 »ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤¢¤ë¡£
212 .TP
213 .B ELOOP
214 .\"O Too many symbolic links were encountered in translating the pathname.
215 ¥Ñ¥¹Ì¾¤ò²ò¼á¤¹¤ëºÝ¤Ë¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤¬Â¿¤¹¤®¤¿¡£
216 .TP
217 .B ENAMETOOLONG
218 .\"O A component of a pathname exceeded 255 characters,
219 .\"O or an entire pathname exceeded 1023 characters.
220 ¥Ñ¥¹Ì¾Ãæ¤Î¥Ç¥£¥ì¥¯¥È¥ê̾¤¬ 255 Ê¸»ú¤ò±Û¤¨¤Æ¤¤¤ë¡¢¤â¤·¤¯¤Ï¥Ñ¥¹Ì¾Á´ÂΤ¬
221 1023 Ê¸»ú¤ò±Û¤¨¤Æ¤¤¤ë¡£
222 .TP
223 .B ENOENT
224 .\"O The named file does not exist.
225 »ØÄꤵ¤ì¤¿Ì¾Á°¤Î¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤¡£
226 .TP
227 .B ENOTDIR
228 .\"O A component of the path prefix is not a directory.
229 ¥Ñ¥¹Ì¾Ãæ¤Î¹àÌܤ˥ǥ£¥ì¥¯¥È¥ê¤Ç¤Ï¤Ê¤¤¤â¤Î¤¬Æþ¤Ã¤Æ¤¤¤ë¡£
230 .TP
231 .B EPERM
232 .\" This happens for at least MSDOS and VFAT file systems
233 .\" on kernel 2.6.13
234 .\"O The underlying file system does not support extending
235 .\"O a file beyond its current size.
236 ²¼Áؤˤ¢¤ë¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Ç¤Ï¡¢¸½ºß¤Î¥Õ¥¡¥¤¥ëŤò±Û¤¨¤Æ
237 ¥Õ¥¡¥¤¥ë¤ò¿­Ä¹¤¹¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤¡£
238 .TP
239 .B EROFS
240 .\"O The named file resides on a read-only file system.
241 »ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤ÏÆɤ߽Ф·ÀìÍѤΥե¡¥¤¥ë¥·¥¹¥Æ¥àÃæ¤Ë¤¢¤ë¡£
242 .TP
243 .B ETXTBSY
244 .\"O The file is a pure procedure (shared text) file that is being executed.
245 »ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï¼Â¹Ô¤µ¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë¡£
246 .PP
247 .\"O For
248 .\"O .BR ftruncate ()
249 .\"O the same errors apply, but instead of things that can be wrong with
250 .\"O .IR path ,
251 .\"O we now have things that can be wrong with the file descriptor,
252 .\"O .IR fd :
253 .BR ftruncate  ()
254 ¤Ë¤âƱÍͤΥ¨¥é¡¼¤¬Å¬ÍѤµ¤ì¤ë¡£
255 ⤷¡¢
256 .I path
257 ¤Ë´Ø¤¹¤ë¥¨¥é¡¼¤Î¾ì¹ç¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼
258 .I fd
259 ¤Ë´Ø¤¹¤ë¥¨¥é¡¼¤È¤Ê¤ë¡£
260 .TP
261 .B EBADF
262 .\"O .I fd
263 .\"O is not a valid descriptor.
264 .I fd
265 ¤¬Ìµ¸ú¤Ê¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼¤Ç¤¢¤ë¡£
266 .TP
267 .\"O .BR EBADF " or " EINVAL
268 .BR EBADF " ¤Þ¤¿¤Ï " EINVAL
269 .\"O .I fd
270 .\"O is not open for writing.
271 .I fd
272 ¤Ç»ØÄꤵ¤ì¤Æ¤¤¤ë¤â¤Î¤¬½ñ¤­¹þ¤ß¥â¡¼¥É¤Ç³«¤«¤ì¤Æ¤¤¤Ê¤¤¡£
273 .TP
274 .B EINVAL
275 .\"O .I fd
276 .\"O does not reference a regular file.
277 .I fd
278 ¤¬Ä̾ï¤Î¥Õ¥¡¥¤¥ë¤ò»²¾È¤·¤Æ¤¤¤Ê¤¤¡£
279 .\"O .SH "CONFORMING TO"
280 .SH ½àµò
281 .\"O 4.4BSD, SVr4, POSIX.1-2001 (these calls first appeared in 4.2BSD).
282 4.4BSD, SVr4, POSIX.1-2001 (¤³¤ì¤é¤Î¥³¡¼¥ë¤Ï 4.2BSD ¤Ç½é¤á¤ÆÅо줷¤¿)¡£
283 .\"O .\" POSIX 1003.1-1996 has
284 .\"O .\" .BR ftruncate ().
285 .\"O .\" POSIX.1-2001 also has
286 .\"O .\" .BR truncate (),
287 .\"O .\" as an XSI extension.
288 .\"O .\" .LP
289 .\"O .\" SVr4 documents additional
290 .\"O .\" .BR truncate ()
291 .\"O .\" error conditions EMFILE, EMULTIHP, ENFILE, ENOLINK.  SVr4 documents for
292 .\"O .\" .BR ftruncate ()
293 .\"O .\" an additional EAGAIN error condition.
294 .\" POSIX 1003.1-1996 ¤Ë¤Ï
295 .\" .BR ftruncate ()
296 .\" ¤¬¤¢¤ë¡£
297 .\" POSIX.1-2001 ¤Ë¤Ï
298 .\" XSI ³ÈÄ¥¤È¤·¤Æ
299 .\" .BR truncate ()
300 .\" ¤â¤¢¤ë¡£
301 .\" .LP
302 .\" SVr4 ¤Ë¤Ï¾¤Î¥¨¥é¡¼¥³¡¼¥É¤È¤·¤Æ¡¢
303 .\" .BR truncate ()
304 .\" ¤Ë¤Ï EMFILE, EMULTIHP, ENFILE, ENOLINK ¤¬¡¢
305 .\" .BR ftruncate ()
306 .\" ¤Ë¤Ï EAGAIN ¤¬¤½¤ì¤¾¤ìµ­½Ò¤µ¤ì¤Æ¤¤¤ë¡£
307 .\"O .SH NOTES
308 .SH Ãí°Õ
309 .\"O The above description is for XSI-compliant systems.
310 .\"O For non-XSI-compliant systems, the POSIX standard allows
311 .\"O two behaviors for
312 .\"O .BR ftruncate ()
313 .\"O when
314 .\"O .I length
315 .\"O exceeds the file length
316 .\"O (note that
317 .\"O .BR truncate ()
318 .\"O is not specified at all in such an environment):
319 .\"O either returning an error, or extending the file.
320 ¾åµ­¤Îµ­½Ò¤Ï XSI ½àµò¤Î¥·¥¹¥Æ¥à¤Î¤â¤Î¤Ç¤¢¤ë¡£
321 XSI Èó½àµò¤Î¥·¥¹¥Æ¥à¤Î¾ì¹ç¡¢POSIX É¸½à¤Ï
322 .BR ftruncate ()
323 ¤ËÂФ·¤Æ
324 .I length
325 ¤¬¥Õ¥¡¥¤¥ë¤ÎŤµ¤è¤êŤ«¤Ã¤¿¾ì¹ç¡¢
326 ¥¨¥é¡¼¤òÊÖ¤¹¤«¥Õ¥¡¥¤¥ë¤ò¿­Ä¥¤¹¤ë¤«¤ÎÆó¤Ä¤ÎÆ°ºî¤òµöÍƤ·¤Æ¤¤¤ë¡£
327 .BR truncate ()
328 ¤ËÂФ·¤Æ¤ÏÁ´¤¯µ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
329 .\"O Like most Unix implementations, Linux follows the XSI requirement
330 .\"O when dealing with native file systems.
331 .\"O However, some nonnative file systems do not permit
332 .\"O .BR truncate ()
333 .\"O and
334 .\"O .BR ftruncate ()
335 .\"O to be used to extend a file beyond its current length:
336 .\"O a notable example on Linux is VFAT.
337 ¤Û¤È¤ó¤É¤Î Unix ¼ÂÁõ¤ÈƱÍÍ¡¢Linux ¤Ï¥Í¥¤¥Æ¥£¥Ö (Linux Í³Íè) ¤Î
338 ¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Î°·¤¤¤Ç¤Ï XSI Í×µá»ÅÍͤˤ·¤¿¤¬¤Ã¤Æ¤¤¤ë¡£
339 ¤·¤«¤·¤Ê¤¬¤é¡¢¤¤¤¯¤Ä¤«¤ÎÈó¥Í¥¤¥Æ¥£¥Ö¤Î¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
340 .BR truncate ()
341 ¤ä
342 .BR ftruncate ()
343 ¤ò»È¤Ã¤Æ¸½ºß¤Î¥Õ¥¡¥¤¥ëŤò±Û¤¨¤Æ¥Õ¥¡¥¤¥ë¤ò¿­Ä¹¤¹¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤¡£
344 Linux ¤Ç¤Îͭ̾¤ÊÎã¤È¤·¤Æ¤Ï VFAT ¤¬¤¢¤ë¡£
345 .\"O .\" At the very least: OSF/1, Solaris 7, and FreeBSD conform, mtk, Jan 2002
346 .\"O .SH "SEE ALSO"
347 .SH ´ØÏ¢¹àÌÜ
348 .BR open (2),
349 .BR stat (2),
350 .BR path_resolution (7)