B
BartC
I think I asked this before but I don't think there was a satisfactory
solution...
I have a bunch of data, some of which might be text, which I might want to
output, sometime, to a file or maybe to stdout, but I don't know (or want to
care) which. Files will always be in binary mode.
The problem is that stdout always works in text mode, and under Windows any
'10' bytes are translated to the two bytes 13 and 10. (And when stdout is
directed to a file, any 13,10 sequences in the original data become
13,13,10, otherwise the extra 13 is harmless).
The question was is there any way of turning stdout into a binary stream so
that it doesn't mess with my data?
I've tried freopen(NULL,"wb",stdout), which didn't work (returns NULL); and
fopen("con:","wb"), which certainly produced output for the console, but it
couldn't be redirected to a file.
All I'm left with is to do stdout output character by character, and 'hold'
any 13 bytes until it's established the next one is not a 10, which is a
hell of a way to solve it (this is implementing a non-C language on top of
the C runtime, which doesn't care for C's text modes..).
(BTW fprintf() doesn't seem to include these extra '13' characters in it's
return value; but according to 7.19.6.1#14, it's suposed to be the number
transmitted.)
solution...
I have a bunch of data, some of which might be text, which I might want to
output, sometime, to a file or maybe to stdout, but I don't know (or want to
care) which. Files will always be in binary mode.
The problem is that stdout always works in text mode, and under Windows any
'10' bytes are translated to the two bytes 13 and 10. (And when stdout is
directed to a file, any 13,10 sequences in the original data become
13,13,10, otherwise the extra 13 is harmless).
The question was is there any way of turning stdout into a binary stream so
that it doesn't mess with my data?
I've tried freopen(NULL,"wb",stdout), which didn't work (returns NULL); and
fopen("con:","wb"), which certainly produced output for the console, but it
couldn't be redirected to a file.
All I'm left with is to do stdout output character by character, and 'hold'
any 13 bytes until it's established the next one is not a 10, which is a
hell of a way to solve it (this is implementing a non-C language on top of
the C runtime, which doesn't care for C's text modes..).
(BTW fprintf() doesn't seem to include these extra '13' characters in it's
return value; but according to 7.19.6.1#14, it's suposed to be the number
transmitted.)