fflush(stdout);
This is more of a basic C thing than a libc ml thing. You should
consider picking up a copy of The C Programming Language by Kernighan
and Ritchie. It will explain all of this.
I know about fflush, thanks.
Consider this program:
int main()
{
char buff[2];
puts("enter a character");
buff[0] = getchar();
buff[1] = '\0';
puts(buff);
return 0;
}
If I compile that on linux-amd64, with or without musl, I will see "enter a character" printed to my console and then be prompted for a character, as opposed to the other way around. I don't know if this is formally guaranteed by the C standard, but somehow that order seems to be maintained.
But if I grep the source code in musl/src/stdio for "fflush" I don't see a bunch of calls to fflush. I see a call to it in fclose and freopen... but that's neither surprising nor helpful. If I do the same in musl/src/internal I also don't get anything. I've even tried just greping for "flush."
And yet somehow the order is maintained within those calls to puts and getchar. So what I'm asking is: how? What part of the internal musl source even attempts to enforce that ordering? I know the calling application can do it with calls to fflush, but somehow that doesn't seem to be necessary short of a signal interrupting the expected flow of execution. Am I just getting lucky 100% of the time or is there some source in the stdio library that's enforcing this?