It seems that when I run the following code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv)
{
int i=0;
setvbuf(stdout, NULL, _IOLBF,0);
while (1)
printf("%d ",i++);
return 0;
}
it prints in chunks of 1024 chars, no matter the size I define for setvbuf().
The question is is if size affects somehow in this case and where is the definition for 1024 chars is coming from.
I don’t know how you identified
1024but it’s probablyBUFSIZ.BUFSIZis defined instdio.h.EDIT
Here’s something
glibcsays:EDIT 2
@larsmans is right. I looked at how
setvbufis implemented and it ignores a call when asking for line buffering and presenting a NULL buf. Now,stdoutis no ordinary file, it’s attached to a terminal. So, heading over to pixelbeat