This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: re-configuring standard input to binary mode


It seems to me that the consle input and output are set binary since the 
following code segment is working fine on my home PC under bash 2.01. 
However, it will not working properly under DOS prompt in which the 
'\x0d' is missing due to the property of text mode.

PS: I use Sergey's patch of gnuwin32.dll, gnuwin32.a, and bash 2.01 
with binary mounting.

int main(int argc, char* argv[]) {
  if( argc == 1) {
    //  ...
    // need to set cout as binary to make this work under DOS !
    // OK with UNIX
    dos2ux( cout, cin);
  }
  else if( argc == 3) {
    ifstream file_in;
    ofstream file_out;
    ...
    file_in.open( argv[1], ios::in | ios::binary);
    file_out.open( argv[2], ios::out | ios::binary);
    ...
  dos2ux( file_out, file_in);
}

void dos2ux( ostream & out, istream & in) {
  char c;

  while( ( c = in.get()) != -1)
    if( c != '\x0d') out << c;
}

Hope this help.

Sincerely,
Wei Ku

***************************************
Department of Physics and Astronomy
The University of Tennessee
1408 Circle Drive
Knoxville, Tennessee 37996-1200
weiku@utkux.utcc.utk.edu
---------------------------------------
Solid State Division
Oak Ridge National Laboratory
P.O.Box 2008
Oak Ridge, TN 37831-6032
Phone: (423) 574-5795
Fax: (423) 574-4143
weiku@solid.ssd.ornl.gov
***************************************

On Mon, 7 Jul 1997, Peter Lu wrote:

> Hi,
> 
> 	How does one configure the standard input stream (fd = 0) to run in
> binary mode?  The default mode seems to be text mode.
> 
> 	I've tried to use fcntl() to no avail.  I've also tried tricks
> like dup() and fdopen().
> 
> 	Thanks for any help.
> 
> Peter Lu (swift@world.std.com)
> -
> For help on using this list (especially unsubscribing), send a message to
> "gnu-win32-request@cygnus.com" with one line of text: "help".
> 
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]