Standards / Extensions | C or C++ | Dependencies |
---|---|---|
Language Environment | both |
#include <stdio.h>
#include <stdio_ext.h>
size_t __fbufsize(FILE *stream);
The __fbufsize() function retrieves the buffer size, in bytes, of the specified stream.
The __fbufsize() function returns the size of the buffer in bytes. Otherwise, the __fbufsize() function returns 0. If an error has occurred, __fbufsize() returns 0 and sets errno to nonzero.
An application wishing to check for error situations should set errno to 0, then call __fbufsize(), and then check errno. If errno is nonzero, assume that an error has occurred.
/* CELEBF87
This example determines the size of the I/O buffer
for an open stream.
*/
#include <stdio.h>
#include <stdio_ext.h>
void main() {
FILE *f;
int bufsize = 0;
char filename[FILENAME_MAX] = "myfile.dat";
f = fopen(filename,"wb");
if (f == NULL) {
perror("fopen failed\n");
return;
}
bufsize = __fbufsize(f);
printf("The buffer size for %s is %d\n",filename,bufsize);
return;
}
The buffer size for myfile.dat is 4096