1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
.\" 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
.\"
.\" Translated into Spanish Sat Mar 7 20:59:39 CET 1998 by Gerardo
.\" Aburruzaga Garca <gerardo.aburruzaga@uca.es>
.\" Correction, Sun, 11 Apr 1999 15:55:18, Martin Vicente <martin@netadmin.dgac.fr>
.\" Translation revised Sat Jun 26 1999 by Juan Piernas <piernas@ditec.um.es>
.\"
.TH SETBUF 3 "29 Noviembre 1993" "BSD" "Manual del Programador de Linux"
.SH NOMBRE
setbuf, setbuffer, setlinebuf, setvbuf \- operaciones sobre bferes
de flujos
.SH SINOPSIS
.na
.B #include <stdio.h>
.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 DESCRIPCIN
Los tres tipos disponibles de estrategias de asignacin de bferes son sin
bfer, con bfer de bloque, y con bfer de lnea. Cuando un flujo de
salida est sin bfer, la informacin aparece en el fichero de destino
o en la terminal tan pronto como se escribe; cuando est con bfer de
bloque se guardan y escriben muchos caracteres como un bloque; cuando
est con bfer de lnea los caracteres se van guardando hasta que se
da un salto de lnea o si la entrada se lee de cualquier flujo
asociado a un dispositivo de terminal (normalmente la entrada estndar
stdin). Se puede emplear la funcin
.BR fflush (3)
para forzar la escritura del bloque ms pronto de la cuenta.
(Vea
.BR fclose (3).)
Normalmente todos los ficheros son de bfer de bloque. Cuando ocurre
la primera operacin de E/S en un fichero, se llama a
.BR malloc (3)
y se obtiene un bfer. Si un flujo se refiere a una terminal (como
hace normalmente
.IR stdout )
es de bfer de lnea. La salida estndar de errores
.I stderr
siempre es sin bfer por defecto.
.PP
La funcin
.B setvbuf
puede emplearse en cualquier momento en cualquier flujo abierto para
cambiar su bfer.
El parmetro
.I modo
debe ser una de las tres macros siguientes:
.RS
.TP
.B _IONBF
sin bfer
.TP
.B _IOLBF
bfer de lnea
.TP
.B _IOFBF
bfer completo
.RE
.PP
Salvo para ficheros sin bfer, el argumento
.I buf
debera apuntar a un bfer de al menos
.I tam
bytes de grande; este bfer se utilizar en lugar del actual. Si el
argumento
.I buf
es
.BR NULL ,
slo el modo se ve afectado; se obtendr un nuevo bfer en la
siguiente operacin de lectura o escritura. La funcin
.I setvbuf
puede emplearse en cualquier momento, pero solamente puede cambiar el
modo de un flujo cuando no est ``activo''; esto es, antes de
cualquier E/S, o inmediatamente tras una llamada a
.BR fflush .
.PP
Las otras tres funciones son, en efecto, simplemente otras formas
simplificadas de llamar a
.BR setvbuf .
La funcin
.B setbuf
es exactamente equivalente a la llamada
.PP
.RS
setvbuf(flujo, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
.RE
.PP
La funcin
.B setbuffer
es lo mismo, excepto en que el tamao del bfer se deja a la
discrecin del usuario, en vez de estar determinado por el valor por
omisin
.BR BUFSIZ .
La funcin
.B setlinebuf
es exactamente equivalente a la llamada:
.PP
.RS
setvbuf(flujo, (char *)NULL, _IOLBF, 0);
.RE
.SH "VASE TAMBIN"
.BR fopen "(3), " fclose "(3), " fflush "(3), " fread "(3), " malloc "(3), "
.BR puts "(3), " printf (3)
.SH CONFORME A
Las funciones
.B setbuf
y
.B setvbuf
son conformes al estndar ANSI C3.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 pueden
no estar disponibles bajo Linux. En sistemas 4.2BSD y 4.3BSD,
.B setbuf
siempre emplea un tamao de bfer por debajo del ptimo, y debe ser
evitada.
.P
Ud. debe asegurarse de que tanto
.I buf
como el espacio al que apunte todava existan cuando
.I flujo
se cierre, que tambin ocurre al acabarse el programa.
.P
Por ejemplo, lo siguiente est mal:
.nf
.sp
#include <stdio.h>
int main()
{
auto char buf[BUFSIZ];
setbuf(stdin, buf);
printf("Hola a todos!\\n");
return 0; /* Se destruye buf, se cierra stdin */
}
.fi
.sp
|