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 2009-02-28 "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)):
69 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
70 .RB ( feature_test_macros (7)
76 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
79 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _POSIX_C_SOURCE\ >=\ 200112L
87 .\"O functions cause the regular file named by
91 .\"O to be truncated to a size of precisely
94 .\"O If the file previously was larger than this size, the extra data is lost.
98 ¤Ç»ØÄꤵ¤ì¤ë¥Õ¥¡¥¤¥ë¤ò¡¢
102 ¤Ç»²¾È¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¤ò
104 ¥Ð¥¤¥È¤ÎŤµ¤Ë¤Ê¤ë¤è¤¦¤Ë±äŤ¹¤ë¡¢¤â¤·¤¯¤ÏÀÚ¤êµÍ¤á¤ë¡£
105 ¤â¤·ÀÚ¤êµÍ¤á¤ëÁ°¤Î¥Õ¥¡¥¤¥ë¤¬
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 ¤â¤·ÀÚ¤êµÍ¤á¤ëÁ°¤Î¥Õ¥¡¥¤¥ë¤¬
112 ¤è¤êû¤«¤±¤ì¤Ð¡¢¿Ä¥¤µ¤ì¤ë¡£
113 ¿Ä¥¤µ¤ì¤¿Éôʬ¤òÆɤó¤À¾ì¹ç¤Ï NULL ¥Ð¥¤¥È (\(aq\\0\(aq) ¤ÎÎó¤¬ÊÖ¤µ¤ì¤ë¡£
115 .\"O The file offset is not changed.
116 ¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
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
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 (¤½¤ì¤¾¤ìºÇ½ª¾õÂÖÊѹ¹»þ¹ï¡¢ºÇ½ª½¤Àµ»þ¹ï;
128 ¤Þ¤¿¡¢set-user-ID ¤È set-group-ID ¤Îµö²Ä¥Ó¥Ã¥È¤¬¥¯¥ê¥¢¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
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.
136 ¤Î¾ì¹ç¡¢¥Õ¥¡¥¤¥ë¤Ï½ñ¤¹þ¤ßÍѤ˳«¤¤¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
138 ¤Î¾ì¹ç¡¢¥Õ¥¡¥¤¥ë¤Ï½ñ¤¹þ¤ß²Äǽ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
139 .\"O .SH "RETURN VALUE"
141 .\"O On success, zero is returned.
142 .\"O On error, \-1 is returned, and
144 .\"O is set appropriately.
145 À®¸ù¤·¤¿¾ì¹ç 0 ¤¬Ê֤롣¼ºÇÔ¤·¤¿¾ì¹ç \-1 ¤¬Ê֤ꡢ
147 ¤¬¥¨¥é¡¼¤ÎÆâÍƤ˽¾¤Ã¤ÆÀßÄꤵ¤ì¤ë¡£
151 .\"O .BR truncate ():
153 ¤Ç¤Ï°Ê²¼¤Î¥¨¥é¡¼¥³¡¼¥É¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
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.
159 .\"O .BR path_resolution (7).)
160 ¥Ñ¥¹¤Ç»ØÄꤵ¤ì¤Æ¤¤¤ë¥Ç¥£¥ì¥¯¥È¥ê¤Ë¸¡º÷µö²Ä¤Î¤Ê¤¤¤â¤Î¤¬¤¢¤ë
161 (ÌõÃí:x ¥Ó¥Ã¥È¤¬Î©¤Ã¤Æ¤¤¤Ê¤¤)¡£
162 ¤¢¤ë¤¤¤Ï¡¢»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤ËÂФ¹¤ë½ñ¤¹þ¤ßµö²Ä¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£
163 .RB ( path_resolution (7)
168 .\"O points outside the process's allocated address space.
170 ¤¬¥×¥í¥»¥¹¤Ë³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤ë¥¢¥É¥ì¥¹¶õ´Ö³°¤ò»Ø¤·¤Æ¤¤¤ë¡£
175 .\"O is larger than the maximum file size. (XSI)
178 ¤¬ºÇÂç¥Õ¥¡¥¤¥ë¥µ¥¤¥º¤è¤êÂ礤¤¡£(XSI)
181 .\"O A signal was caught during execution.
182 ¼Â¹ÔÃæ¤Ë¥·¥°¥Ê¥ë¤ò¼õ¤±¤¿¡£
187 .\"O is negative or larger than the maximum file size.
190 ¤¬Éé¿ô¤Ç¤¢¤ë¤«¡¢ºÇÂç¥Õ¥¡¥¤¥ë¥µ¥¤¥º¤è¤êÂ礤¤¡£
193 .\"O An I/O error occurred updating the inode.
194 inode ¤Î¹¹¿·»þ¤Ë I/O ¥¨¥é¡¼¤¬È¯À¸¤·¤¿¡£
197 .\"O While blocked waiting to complete,
198 .\"O the call was interrupted by a signal handler; see
202 ´°Î»ÂÔ¤Á¤ÇÄä»ß (block) ¤·¤Æ¤¤¤ë´Ö¤Ë¡¢¸Æ¤Ó½Ð¤·¤¬
203 ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿¡£
210 .\"O The named file is a directory.
211 »ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤¢¤ë¡£
214 .\"O Too many symbolic links were encountered in translating the pathname.
215 ¥Ñ¥¹Ì¾¤ò²ò¼á¤¹¤ëºÝ¤Ë¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤¬Â¿¤¹¤®¤¿¡£
218 .\"O A component of a pathname exceeded 255 characters,
219 .\"O or an entire pathname exceeded 1023 characters.
220 ¥Ñ¥¹Ì¾Ãæ¤Î¥Ç¥£¥ì¥¯¥È¥ê̾¤¬ 255 ʸ»ú¤ò±Û¤¨¤Æ¤¤¤ë¡¢¤â¤·¤¯¤Ï¥Ñ¥¹Ì¾Á´ÂΤ¬
221 1023 ʸ»ú¤ò±Û¤¨¤Æ¤¤¤ë¡£
224 .\"O The named file does not exist.
225 »ØÄꤵ¤ì¤¿Ì¾Á°¤Î¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤¡£
228 .\"O A component of the path prefix is not a directory.
229 ¥Ñ¥¹Ì¾Ãæ¤Î¹àÌܤ˥ǥ£¥ì¥¯¥È¥ê¤Ç¤Ï¤Ê¤¤¤â¤Î¤¬Æþ¤Ã¤Æ¤¤¤ë¡£
232 .\" This happens for at least MSDOS and VFAT file systems
234 .\"O The underlying file system does not support extending
235 .\"O a file beyond its current size.
236 ²¼Áؤˤ¢¤ë¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Ç¤Ï¡¢¸½ºß¤Î¥Õ¥¡¥¤¥ëŤò±Û¤¨¤Æ
237 ¥Õ¥¡¥¤¥ë¤ò¿Ä¹¤¹¤ë¤³¤È¤¬¤Ç¤¤Ê¤¤¡£
240 .\"O The named file resides on a read-only file system.
241 »ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤ÏÆɤ߽Ф·ÀìÍѤΥե¡¥¤¥ë¥·¥¹¥Æ¥àÃæ¤Ë¤¢¤ë¡£
244 .\"O The file is a pure procedure (shared text) file that is being executed.
245 »ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï¼Â¹Ô¤µ¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë¡£
248 .\"O .BR ftruncate ()
249 .\"O the same errors apply, but instead of things that can be wrong with
251 .\"O we now have things that can be wrong with the file descriptor,
254 ¤Ë¤âƱÍͤΥ¨¥é¡¼¤¬Å¬ÍѤµ¤ì¤ë¡£
257 ¤Ë´Ø¤¹¤ë¥¨¥é¡¼¤Î¾ì¹ç¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼
259 ¤Ë´Ø¤¹¤ë¥¨¥é¡¼¤È¤Ê¤ë¡£
263 .\"O is not a valid descriptor.
265 ¤¬Ìµ¸ú¤Ê¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼¤Ç¤¢¤ë¡£
267 .\"O .BR EBADF " or " EINVAL
268 .BR EBADF " ¤Þ¤¿¤Ï " EINVAL
270 .\"O is not open for writing.
272 ¤Ç»ØÄꤵ¤ì¤Æ¤¤¤ë¤â¤Î¤¬½ñ¤¹þ¤ß¥â¡¼¥É¤Ç³«¤«¤ì¤Æ¤¤¤Ê¤¤¡£
276 .\"O does not reference a regular file.
278 ¤¬Ä̾ï¤Î¥Õ¥¡¥¤¥ë¤ò»²¾È¤·¤Æ¤¤¤Ê¤¤¡£
279 .\"O .SH "CONFORMING TO"
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.
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 ¤Ë¤Ï
297 .\" POSIX.1-2001 ¤Ë¤Ï
302 .\" SVr4 ¤Ë¤Ï¾¤Î¥¨¥é¡¼¥³¡¼¥É¤È¤·¤Æ¡¢
304 .\" ¤Ë¤Ï EMFILE, EMULTIHP, ENFILE, ENOLINK ¤¬¡¢
306 .\" ¤Ë¤Ï EAGAIN ¤¬¤½¤ì¤¾¤ìµ½Ò¤µ¤ì¤Æ¤¤¤ë¡£
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 ()
315 .\"O exceeds the file length
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 ɸ½à¤Ï
325 ¤¬¥Õ¥¡¥¤¥ë¤ÎŤµ¤è¤êŤ«¤Ã¤¿¾ì¹ç¡¢
326 ¥¨¥é¡¼¤òÊÖ¤¹¤«¥Õ¥¡¥¤¥ë¤ò¿Ä¥¤¹¤ë¤«¤ÎÆó¤Ä¤ÎÆ°ºî¤òµöÍƤ·¤Æ¤¤¤ë¡£
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
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 ¤·¤«¤·¤Ê¤¬¤é¡¢¤¤¤¯¤Ä¤«¤ÎÈó¥Í¥¤¥Æ¥£¥Ö¤Î¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
343 ¤ò»È¤Ã¤Æ¸½ºß¤Î¥Õ¥¡¥¤¥ëŤò±Û¤¨¤Æ¥Õ¥¡¥¤¥ë¤ò¿Ä¹¤¹¤ë¤³¤È¤¬¤Ç¤¤Ê¤¤¡£
344 Linux ¤Ç¤ÎÍ̾¤ÊÎã¤È¤·¤Æ¤Ï VFAT ¤¬¤¢¤ë¡£
345 .\"O .\" At the very least: OSF/1, Solaris 7, and FreeBSD conform, mtk, Jan 2002
350 .BR path_resolution (7)