https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84815
Bug ID: 84815 Summary: gcc fwrite failed write to stdout in binary mode (Win7) Product: gcc Version: 7.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: albertmcchan at yahoo dot com Target Milestone: --- #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { size_t n = 64*1024; // code ok if below 64k char* buf = malloc(n); if (buf == NULL) return 1; memset(buf, 'O', n); buf[n-1] = 'X'; // signal for last byte setmode(STDOUT_FILENO, _O_BINARY); // <-- this caused the bug n = fwrite(buf, 1, n, stdout); // fwrite failed, but why ? printf("\nfwrite %d bytes\n", n); // output: fwrite 0 bytes free(buf); return 0; }