setvbuf() call in init causes a warning/error on Windows #4884

issue Diapolo opened this issue on September 9, 2014
  1. Diapolo commented at 1:02 PM on September 9, 2014: none

    https://github.com/bitcoin/bitcoin/blob/master/src/init.cpp#L633 setvbuf(stdout, NULL, _IOLBF, 0); causes this warning to be displayed in my IDE: Invalid parameter passed to C runtime function.

    Replacing _IOLBF by _IONBF resolves it. I have no idea yet, if we should guard the call by an #ifdef on Windows.

  2. jgarzik commented at 1:20 PM on September 9, 2014: contributor

    Changing to _IONBF makes output significantly slower in some programs.

  3. laanwj commented at 1:22 PM on September 9, 2014: member

    Why do we change this for stdout at all?

    The only case in which we print to stdout at all is on -logtoconsole, and printing to the console arguably works fine without changing obscure stream options.

  4. Diapolo commented at 5:26 PM on September 9, 2014: none

    @jgarzik I didn't want to say _IONBF is the solution, it just makes the warning/error go away. @laanwj I don't know, perhaps we should just remove it then?

    Edit: It was added via this pull: https://github.com/bitcoin/bitcoin/commit/283e405c063acfca304acbff505badcbbcb814c9

  5. ajweiss commented at 11:28 PM on September 9, 2014: contributor

    I think the warning is being thrown because it looks like Windows setvbuf() doesn't ignore the size argument (and instead use the default) when you ask it to allocate its own buffer with buf=NULL. It probably doesn't make sense to enable the buffers on Windows anyway as it doesn't support line buffering and it would be pretty annoying to have block buffered output on the console.

    With respect to why it's in there: Linux uses full buffering instead of line buffering for stdout if it isn't pointing to a terminal and it looks like systemd has some stdout/stderr log redirection stuff where line buffering behavior would be desirable.

    Maybe a better solution: Drop it altogether and add an fflush(stdout) to LogPrintStr() in the fPrintToConsole block after the fwrite() to stdout.

  6. sipa commented at 12:10 AM on September 10, 2014: member

    @ajweiss sound good to me.

  7. laanwj commented at 7:49 AM on September 10, 2014: member

    SGTM too. Better to have an explicit fflush instead of changing the properties of stdout.

  8. jgarzik commented at 12:36 PM on September 10, 2014: contributor

    +1

  9. laanwj closed this on Sep 11, 2014

  10. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-20 09:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me