[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


setvbuf

Change the buffering scheme for a stream.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdio.h>
int setvbuf(FILE *stream, char *buf, int mode, 
   size_t size);
Parameters:

Parameters for this facility are:

stream  
FILE *  
A pointer to a FILE stream  
buf  
char *  
A buffer for input and output  
mode  
int  
A buffering mode  
size  
size_t  
The size of the buffer  

Remarks:

The setvbuf() allows the manipulation of the buffering scheme as well as the size of the buffer used by stream. The function should be called after the stream is opened but before it is written to or read from.

The buf argument is a pointer to a character array. The size argument indicates the size of the character array pointed to by buf. The most efficient buffer size is a multiple of BUFSIZ, defined in stdio.h.

If buf is a null pointer, then the operating system creates its own buffer of size bytes.

The mode argument specifies the buffering scheme to be used with stream. mode can have one of three values defined in stdio.h: _IOFBF, _IOLBF, and _IONBF.

setvbuf() returns zero if it is successful and returns a nonzero value if it fails.

See Also:

"setbuf"

"malloc"

Example of setvbuf() usage.:
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	FILE *f;
	char name[80];
	
	// get a filename from the user
	printf("Enter the name of the file to write to.\n");
	gets(name);

	// create a new file for output
	if ( (f = fopen(name, "w")) == NULL) {
		printf("Can't open file %s.\n", name);
		exit(1);
	}

	setvbuf(f, NULL, _IOLBF, 0);	// line buffering
	fprintf(f, "This file is now\n");
	fprintf(f, "line buffered.\n");

	// close the file
	fclose(f);

	return 0;
}

Output:
Enter the name of the file to write to.
buffy


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000