www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/05/30/04:25:57

From: Eric Backus <ericb AT lsid DOT hp DOT com>
Subject: Re: stdin, stdout and friends, was: fstat() yet again
To: mcastle AT umr DOT edu
Date: Mon, 30 May 94 1:00:56 PDT
Cc: eliz AT is DOT elta DOT co DOT il, djgpp AT sun DOT soe DOT clarkson DOT edu (djgpp)
Mailer: Elm [revision: 70.85]

Mike Castle wrote:
> Amazingly enough eliz AT is DOT elta DOT co DOT il said:
> > My question is: is there ANY way to change open mode (TEXT vs
> > BINARY) of the stdin stream WITHOUT reopening it (which we
> > obviously cannot do, as indicated by Eric Backus)?  I think there
> > is no PORTABLE (i.e. ANSI) way, but maybe something DOS-specific
> > or DJGPP-specific?
> 
> setmode(fileno(FILE*),O_BINARY);

Yes, this is the solution.  The only thing I would add is: don't
forget about buffering.  For example, if you write a line in text mode
with fprintf(), then switch to binary mode, and then write a block,
the stdio buffering may cause you problems.  When there is any doubt,
I've found it best to fflush() before doing setmode().
--
				Eric Backus
				ericb AT lsid DOT hp DOT com
				(206) 335-2495

- Raw text -


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