What is the simplest way to write to stdout in binary mode?
You can do something like that (which is sort of cross platform):
FILE *const in = fdopen(dup(fileno(stdin)), "rb");FILE *const out = fdopen(dup(fileno(stdout)), "wb");/* ... */fclose(in);fclose(out);
Or you can use write()
and read()
system calls directly with fileno(stdin)
and fileno(stdout)
. Those system calls operate on lower level and don't do any conversions. But they also don't have buffering that you get from FILE
streams.