Mono Class Library: Mono.Unix.Native.Stdlib Overview | Members

Mono.Unix.Native.Stdlib.setvbuf Method

Control FILE stream buffering operations. [Edit]

[System.CLSCompliant(false)]
public static int setvbuf (IntPtr stream, byte* buf, int mode, ulong size)

Parameters

stream
The FILE stream to set buffering behavior on. [Edit]
buf
The buffer to use for buffering. [Edit]
mode
The type of buffering to start using with stream. [Edit]
size
The size of the buffer buf. [Edit]

Returns

The setvbuf() function returns 0 on success, or Stdlib.EOF if the request cannot be honored (note that the stream is still functional in this case). [Edit]

Remarks

The three types of buffering available are unbuffered, block buffered, and line buffered. When an output stream is unbuffered, information appears on the destination file or terminal as soon as written; when it is block buffered many characters are saved up and written as a block; when it is line buffered characters are saved up until a new- line is output or input is read from any stream attached to a terminal device (typically Stdlib.stdin). The function Stdlib.fflush(3) may be used to force the block out early. (See Stdlib.fclose(3).)

Normally all files are block buffered. When the first I/O operation occurs on a file, Stdlib.malloc(3) is called, and an optimally-sized buffer is obtained. If a stream refers to a terminal (as Stdlib.stdout normally does) it is line buffered. The standard error stream Stdlib.stderr is always unbuffered.

The setvbuf function may be used to alter the buffering behavior of a stream. The mode argument must be one of the following three values:

ValueDescription
Stdlib._IONBFunbuffered
Stdlib._IOLBFline buffered
Stdlib._IOFBFfully buffered

The size argument may be given as zero to obtain deferred optimal-size buffer allocation as usual. If it is not zero, then except for unbuffered files, the buf argument should point to a buffer at least size bytes long; this buffer will be used instead of the current buffer. If buf is not null, it is the caller's responsibility to Stdlib.free(3) this buffer after closing the stream.

The setvbuf() function may be used at any time, but may have peculiar side effects (such as discarding input or flushing output) if the stream is ''active''. Portable applications should call it only once on any given stream, and before any I/O is performed.

[Edit]

Requirements

Namespace: Mono.Unix.Native
Assembly: Mono.Posix (in Mono.Posix.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0