The function fgets()
is part of the stdio package, and as such it must buffer (or not) the input stream in a way that is consistent with also using fgetc()
, fscanf()
, fread()
and so forth. That means that the buffer itself (if the stream is buffered) is the property of the FILE
object.
Whether there is a buffer or not, and if buffered, how large the buffer is, can be suggested to the library by calling setvbuf()
.
The library implementation has a fair amount of latitude to ignore hints and do what it thinks best, but buffers that are "reasonable" powers of two in size will usually be accepted. You've noticed that the default was 4096, which is clearly smaller than optimal.
The stream is buffered by default if it is opened on an actual file. Its buffering on a pipe, FIFO, TTY or anything else potentially has different defaults.