.\" Copyright (c) 1983, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)truncate.2 6.9 (Berkeley) 3/10/91 .\" .\" Modified Sat Jul 24 12:46:33 1993 by Rik Faith .\" Modified Tue Oct 22 22:36:33 1996 by Eric S. Raymond .\" Modified Mon Dec 21 13:37:05 1998 by Andries Brouwer .\" Modified 7 Jan 2002, Michael Kerrisk .\" Modified 2002-04-06, aeb .\" .\" Translated by Urko Lusa 19980210 .\" Translation revised May 1 1998 by Juan Piernas with .\" fixes from Nicolás Lichtmaier .\" Modified Mon Dec 21 13:37:05 1998 by Andries Brouwer (aeb@cwi.nl) .\" Translation revised on Tue Apr 6 1999 by Juan Piernas .\" Revisado por Miguel Pérez Ibars el 1-diciembre-2004 .\" .TH TRUNCATE 2 "21 diciembre 1998" "Linux" "Manual del programador de Linux" .SH NOMBRE truncate, ftruncate \- trunca un fichero a una longitud especificada .SH SINOPSIS .B #include .br .B #include .sp .BI "int truncate(const char *" path ", off_t " length ); .br .BI "int ftruncate(int " fd ", off_t " length ); .SH DESCRIPCIÓN Las funciones .B truncate y .B ftruncate hacen que el fichero regular cuyo nombre es .I path o que es referenciado por .I fd sea truncado a un tamaño de .I length bytes. .LP Si el fichero era previamente más grande que este tamaño, los datos extra se pierden. Si el fichero era previamente más pequeño, es extendido, y la zona ampliada es rellenada con bytes cero. .LP El puntero del fichero no se modifica. .LP Si el tamaño cambia, los campos ctime y mtime del fichero son actualizados, y los bits de modo suid y sgid pueden ser limpiados. .LP Con .BR ftruncate , el fichero debe estar abierto para escritura; con .BR truncate , el fichero debe ser escribible. .SH "VALOR DEVUELTO" En caso de éxito, se devuelve cero. En caso de error, se devuelve -1 y se establece el .I errno apropiado. .SH ERRORES Para .BR truncate : .TP .B EACCES Se deniega el permiso de búsqueda para un componente del prefijo de la ruta, o el fichero nombrado no puede ser escrito por el usuario. .TP .B EFAULT .I Path apunta fuera del espacio de direcciones asignado al proceso. .TP .B EFBIG El argumento .I length es mayor que el tamaño máximo de fichero. (XSI) .TP .B EINTR Se capturó una señal durante la ejecución. .TP .B EINVAL El argumento .I length es negativo o mayor que el tamaño máximo de fichero. .TP .B EIO Ocurrió un error de E/S mientras se actualizaba el nodo-i. .TP .B EISDIR El fichero nombrado es un directorio. .TP .B ELOOP Demasiados enlaces simbólicos en la traducción del nombre de ruta. .TP .B ENAMETOOLONG Un componente de la ruta excede los 255 caracteres, o la ruta completa excede los 1023 caracteres. .TP .B ENOENT El fichero no existe. .TP .B EROFS El fichero reside en un sistema de ficheros de sólo lectura. .TP .B ETXTBSY El fichero es un fichero de procedimientos puros (código compartido) que se está ejecutando. .PP Para .B ftruncate se aplican los mismos errores, pero en lugar de tratar con .IR path , los errores pueden ocurrir ahora con .IR fd : .TP .B EBADF .I fd no es un descriptor válido. .TP .BR EBADF " o " EINVAL .I fd no está abierto para escritura. .TP .B EINVAL .I fd no hace referencia a un fichero regular. .SH "CONFORME A" 4.4BSD, SVr4 (estas funciones aparecieron por primera vez en BSD 4.2). POSIX 1003.1-1996 posee .BR ftruncate . POSIX 1003.1-2001 posee también .IR truncate , como una extensión de XSI. .LP SVr4 documenta para .B truncate las condiciones de error adicionales EMFILE, EMULTIHP, ENFILE, ENOLINK. SVr4 documenta para .B ftruncate una condición de error adicional EAGAIN. .SH OBSERVACIONES La descripción de arriba es para sistemas conformes con XSI. Para sistemas no conformes con XSI, el estándar POSIX permite dos comportamientos para .B ftruncate cuando .I length excede la longitud del fichero (observe que .B truncate no está especificada en absoluto en tales condiciones): bien devolver un error o extender el fichero. (La mayoría de sistemas UNIX siguen el requisito de XSI.) .\" At the very least: OSF/1, Solaris 7, and FreeBSD conform, mtk, Jan 2002 .SH "VÉASE TAMBIÉN" .BR open (2)