www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/07/26/13:19:05

Xref: news-dnh.mv.net comp.os.msdos.djgpp:1167
Path: news-dnh.mv.net!mv!news.sprintlink.net!tank.news.pipex.net!pipex!sunsite.doc.ic.ac.uk!ulcc.ac.uk!pluto.ulcc.ac.uk!cziwkga
From: cziwkga AT pluto DOT ulcc DOT ac DOT uk (Kevin Ashley)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Text/Binary mode of stdin,stdout,stderr
Date: 25 Jul 1995 11:19:08 GMT
Organization: University of London Computer Centre
Lines: 59
Distribution: world
References: <DC823n DOT 84K AT jade DOT mv DOT net>
Reply-To: k DOT ashley AT ulcc DOT ac DOT uk
Nntp-Posting-Host: pluto.ulcc.ac.uk
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Dj-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019