Mail Archives: djgpp/1995/07/26/13:19:05
In article <DC823n DOT 84K AT jade DOT mv DOT net>, kagel AT quasar DOT bloomberg DOT com writes:
|> <dpsm AT lbrizol DOT com> writes:
|> I'm just starting to play with djgpp v2, and I have a question. How do you
|> set binary or text mode of the standard input and output?
|>
|> From emacs.c:
|>
|> #ifdef MSDOS
|> /* We do all file input/output as binary files. When we need to translate
|> newlines, we do that manually. */
|> _fmode = O_BINARY;
|> (stdin)->_flag &= ~_IOTEXT;
|> (stdout)->_flag &= ~_IOTEXT;
|> (stderr)->_flag &= ~_IOTEXT;
|> #endif /* MSDOS */
|>
|> The #define _IOTEXT is not in stdio.h (it was in previous versions). Is it
|> the same as pre v2? Is there a "portable" or "standard" way to do this in
|> ANS C?
The portable and standard way is with setmode(), as other replies have
indicated. What's being done above is generally bad news ; programs should
treat the FILE * object as an opaque thing and not fiddle with its
insides.
And Art replied:
|>Try closing stdin/stdout and reopening with mode set to binary:
|>
|> fclose( stdin );
|> stdin = fopen( "STDIN", "rb" );
|> fclose( stdout );
|> stdout = fopen( "STDOUT", "wb" );
|>
But I think this is bad news when stdin or stdout are pipes. However,
as DJ has commented, there may be problems with the setmode implementation
for stdout. I did come across this in my port of pbmplus and sox ;
piping together a number of operations didn't seem to work, but
doing them separately did.. i.e.
prog1 a | prog2 | prog3 > file.out
where each of prog1,2,3 do a setmode(,O_BINARY) on input and output
didn't always produce the desired effect but
prog1 a > temp
prog2 < temp > temp2
prog3 <temp2 > file.out
did. I did all this about a year ago and cannot remember the details
but I will try and track it down further with V2, since it will be
easier for me to work out what's going on as Borland's IO routines won't
be involved any more.
------------------------------------------------------------------------------
Kevin Ashley K DOT Ashley AT Ulcc DOT ac DOT uk
Systems Development Group Manager http://www.ulcc.ac.uk/staff/Kevin+Ashley
University of London Computer Centre. ...ukc!ncdlab!K.Ashley
This is not a signature
- Raw text -