Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Buffering Parameters From an Open `FILE*`

Tags:

c

file

buffer

In C, we can use setvbuf(...) to set a buffer, its size, and a buffering mode. I am surprised to find that no one has asked how to read these values, given an open FILE* (e.g. stdout, or user-provided). I.e., how could one implement a "getvbuf(...)" routine (or even a subset of it)?

void getvbuf(FILE* stream, char** pbuf,int* bufmode,size_t* bufsize);
like image 401
imallett Avatar asked Oct 30 '25 18:10

imallett


1 Answers

I don't think its available as part of the standard. However Solaris has introduced some non standard mechanism to query few of these properties which are also available in GNU C compiler.

Check this for more details: https://www.gnu.org/software/libc/manual/html_node/Controlling-Buffering.html

I was curious to know the use case where you want to do a getvbuf(..) kind of stuff.

like image 175
A.N Avatar answered Nov 01 '25 08:11

A.N



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!