File: setbuf.3

package info (click to toggle)
manpages-es 1.55-9
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 7,468 kB
  • ctags: 6
  • sloc: sh: 1,629; makefile: 64
file content (206 lines) | stat: -rw-r--r-- 6,814 bytes parent folder | download | duplicates (4)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
.\" 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 <martin@netadmin.dgac.fr>
.\" Correction,  2000-03-03, Andreas Jaeger <aj@suse.de>
.\" Added return value for setvbuf, aeb, 
.\"
.\" Translated into Spanish Sat Mar  7 20:59:39 CET 1998 by Gerardo
.\" Aburruzaga García <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>
.\" Traducción revisada por Miguel Pérez Ibars <mpi79470@alu.um.es> 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 <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 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 <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
.SH "SEE ALSO"
.BR fclose (3),
.BR fflush (3),
.BR fopen (3),
.BR fread (3),
.BR malloc (3),
.BR printf (3),
.BR puts (3)