Reputation: 2367
My function
void myFunction (FILE *f);
gets an already opened file. I need to write a literal CR+LF
, so I want to set f
's mode to binary.
How can I do that?
Upvotes: 4
Views: 555
Reputation: 26279
As per comments, perhaps a function such as the following may be useful (untested!) :
#include <stdio.h>
#ifdef WIN32
#include <fcntl.h>
#include <io.h>
#endif
int SetBinary(FILE *pFile)
{
// set file mode to binary
#ifdef WIN32
return _setmode(_fileno(pFile), O_BINARY);
#else
return setmode(_fileno(pFile), O_BINARY);
#endif
}
It looks ugly, so maybe you might conditionally #define
the function name instead, but I don't think it's ever going to be pretty.
Upvotes: 2