So, I have a use case where I need to force a C program cross compiled to Windows to read in stdin as a binary format. This works great for Windows compilers, but unfortunately I am compiling this program using MinGW so I can't get access to setting the mode of the stdin as this is a pre-MSDOS, preUNIX convention. How would I force this to occur while still compiling this code in GCC? Any ideas?
The statements at fault are the following:
__setmode(__fileno(stdin), O_BINARY);
__setmode(__fileno(stdout), O_BINARY);
The statements above are not related to the compiler but to the header files and C library you are linking to.
MinGW uses the Microsoft runtime library and compatible header files. You probably have an incorrect spelling for these functions, try removing some of the
_
, grep forsetmode
in the header files, etc:If you cannot find these, copy the prototypes and
#define
from the microsoft headers.cremno suggested this:
If you really cannot find these symbols, try this: