__fbufsize() — Retrieve the buffer size of an open stream

Standards

Standards / Extensions C or C++ Dependencies
Language Environment both  

Format

#include <stdio.h>
#include <stdio_ext.h>

size_t __fbufsize(FILE *stream);

General description

The __fbufsize() function retrieves the buffer size, in bytes, of the specified stream.

Returned value

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.

Error Code
Description
EBADF
The stream specified by stream is not valid.

Example

CELEBF87
/* 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;
}
Output
The buffer size for myfile.dat is 4096

Related information