gcc for WinNT

John R. Dennis jdennis@ultranet.com
Fri Mar 7 17:24:00 GMT 1997


>>>>> "Ron" == Ron G Minnich <rminnich@sarnoff.com> writes:

    Ron> reading in text mode? this is a simple int fd = open("file",
    Ron> O_RDONLY); fd = read(blah blah)

    Ron> How do you control text mode from that? new options or an
    Ron> fcntl?  ron - For help on using this list, send a message to
    Ron> "gnu-win32-request@cygnus.com" with one line of text: "help".

There are many ways to set binary vs. text mode on a file stream.

in fopen add either the b (binary) or the t (text) character in
the mode string, e.g. fopen(filename "rb") to open a file for binary
reading. 

In open() bitwise OR one of _O_BINARY, _O_TEXT flags.

You can call _setmode(handle, mode) where mode is
_O_TEXT or _O_BINARY after a file is open,  for example:

   /* Set "stdin" to have binary mode: */
   result = _setmode( _fileno( stdin ), _O_BINARY );
   if( result == -1 )
      perror( "Cannot set mode" );
   else
      printf( "'stdin' successfully changed to binary mode\n" );


You can set the global variable _fmode. The _fmode variable sets the
default file-translation mode for text or binary translation. It is
declared in STDLIB.H as extern int _fmode;
  
The default setting of _fmode is _O_TEXT, for text-mode
translation. _O_BINARY is the setting for binary mode.  You can change
the value of _fmode in either of two ways: Link with BINMODE.OBJ. This
changes the initial setting of _fmode to _O_BINARY, causing all files
except stdin, stdout, and stderr to be opened in binary mode.
Change the value of _fmode directly by setting it in your program.

Hope that helps,

John Dennis

-
For help on using this list, send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list