Talk:Setvbuf

Hi. I'm working on my own standard implementation for UNIX based systems and, later on, WIN32 systems. This means I've been reading the C99 standard to try and follow it as tight as possible. During my implementation of setbuf and setvbuf I stumbled upon this text:

"Although three types of buffering are defined, an implementation may choose to make one or more of them equivalent. For example, a library may choose to implement line buffering for binary files as equivalent to unbuffered I/O, or it may choose to always implement full buffering as equivalent to line buffering". (page 151 of the C99 rationale)

Thus, meaning that not always will inserting a newline flush a line buffer, because the underlying implementation may choose not to adhere to this behaviour. I, myself, implemented line buffering as full buffering, meaning that the example in this wikipedia article should be marked as incorrect. It is true that, in most implementations, putchar('\n') in these conditions will flush the buffer, but the standard does not guarantee this.

I will check this page back in some days, if nobody disagrees, I'll try to modify the article in such a way that it becomes conformant with the standard.

In fact, after debugging GLIBC's behaviour with the example, it behaves in a different way. the string "he" is written directly to output and not buffered, which is perfectly valid standards compliant.

Thanks, João Ricardo Lourenço (jorl17).