.\" Copyright (c) 1980, 1991 Regents of the University of California. .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" the American National Standards Committee X3, on Information .\" Processing Systems. .\" .\" 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. .\" .\" @(#)setbuf.3 6.10 (Berkeley) 6/29/91 .\" .\" Converted for Linux, Mon Nov 29 14:55:24 1993, faith@cs.unc.edu .\" Added section to BUGS, Sun Mar 12 22:28:33 MET 1995, .\" Thomas.Koenig@ciw.uni-karlsruhe.de .\" Correction, Sun, 11 Apr 1999 15:55:18, .\" Martin Vicente .\" Correction, 2000-03-03, Andreas Jaeger .\" Added return value for setvbuf, aeb, .\" .\" Translated into Spanish Sat Mar 7 20:59:39 CET 1998 by Gerardo .\" Aburruzaga García .\" Correction, Sun, 11 Apr 1999 15:55:18, Martin Vicente .\" Translation revised Sat Jun 26 1999 by Juan Piernas .\" Traducción revisada por Miguel Pérez Ibars el 3-febrero-2005 .\" .TH SETBUF 3 "9 junio 2001" "Linux" "Manual del Programador de Linux" .SH NOMBRE setbuf, setbuffer, setlinebuf, setvbuf \- operaciones sobre búferes de flujos .SH SINOPSIS .na .B #include .sp .BI "void setbuf(FILE *" flujo ", char *" buf ); .br .BI "void setbuffer(FILE *" flujo ", char *" buf ", size_t" tam ); .br .BI "void setlinebuf(FILE *" flujo ); .br .BI "int setvbuf(FILE *" flujo ", char *" buf ", int " modo .BI ", size_t " tam ); .ad .SH DESCRIPCIÓN Los tres tipos disponibles de estrategias de asignación de búferes son sin búfer, con búfer de bloque, y con búfer de línea. Cuando un flujo de salida está sin búfer, la información aparece en el fichero de destino o en la terminal tan pronto como se escribe; cuando está con búfer de bloque se guardan y escriben muchos caracteres como un bloque; cuando está con búfer de línea los caracteres se van guardando hasta que se da un salto de línea o si la entrada se lee de cualquier flujo asociado a un dispositivo de terminal (normalmente la entrada estándar stdin). Se puede emplear la función .BR fflush (3) para forzar la escritura del bloque más pronto de la cuenta. (Vea .BR fclose (3).) Normalmente todos los ficheros son de búfer de bloque. Cuando ocurre la primera operación de E/S en un fichero, se llama a .BR malloc (3) y se obtiene un búfer. Si un flujo se refiere a una terminal (como hace normalmente .IR stdout ) es de búfer de línea. La salida estándar de errores .I stderr siempre es sin búfer por defecto. .PP La función .B setvbuf puede emplearse en cualquier flujo abierto para cambiar su búfer. El parámetro .I modo debe ser una de las tres macros siguientes: .RS .TP .B _IONBF sin búfer .TP .B _IOLBF búfer de línea .TP .B _IOFBF búfer completo .RE .PP Salvo para ficheros sin búfer, el argumento .I buf debería apuntar a un búfer de al menos .I tam bytes de grande; este búfer se utilizará en lugar del actual. Si el argumento .I buf es .BR NULL , sólo el modo se ve afectado; se obtendrá un nuevo búfer en la siguiente operación de lectura o escritura. La función .I setvbuf puede ser usada solamente después de abrir un flujo y antes de que ninguna otra operación se haya realizado sobre él. .PP Las otras tres funciones son, en efecto, simplemente otras formas simplificadas de llamar a .BR setvbuf . La función .B setbuf es exactamente equivalente a la llamada .PP .RS setvbuf(flujo, buf, buf ? _IOFBF : _IONBF, BUFSIZ); .RE .PP La función .B setbuffer es lo mismo, excepto en que el tamaño del búfer se deja a la discreción del usuario, en vez de estar determinado por el valor por omisión .BR BUFSIZ . La función .B setlinebuf es exactamente equivalente a la llamada: .PP .RS setvbuf(flujo, (char *)NULL, _IOLBF, 0); .RE .SH "VALOR DEVUELTO" La función .B setvbuf devuelve 0 en caso de éxito. Puede devolver cualquier valor si falla, pero devuelve un valor distinto de cero cuando .I mode es inválido o la petición no puede ser atendida. Puede modificar .I errno en caso de fallo. Las otras funciones no devuelven ningún valor. .SH CONFORME A Las funciones .B setbuf y .B setvbuf son conformes al estándar ANSI X3.159-1989 (``C ANSI''). .SH FALLOS Las funciones .B setbuffer y .B setlinebuf no son transportables a versiones de BSD anteriores a 4.2BSD, y están disponibles bajo Linux desde libc 4.5.21. En sistemas 4.2BSD y 4.3BSD, .B setbuf siempre emplea un tamaño de búfer por debajo del óptimo, y debe ser evitada. .P Ud. debe asegurarse de que tanto .I buf como el espacio al que apunte todavía existan cuando .I flujo se cierre, que también ocurre al acabarse el programa. .P Por ejemplo, lo siguiente está mal: .nf .sp #include int main() { auto char buf[BUFSIZ]; setbuf(stdin, buf); printf("¡Hola a todos!\\n"); return 0; /* Se destruye buf, se cierra stdin */ } .fi .sp .SH "SEE ALSO" .BR fclose (3), .BR fflush (3), .BR fopen (3), .BR fread (3), .BR malloc (3), .BR printf (3), .BR puts (3)