This is the mail archive of the 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: gcc for WinNT

>>>>> "Ron" == Ron G Minnich <> 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> "" 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

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" );
      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
"" 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]