_setmode

Description

Sets the file translation mode.

#include <fcntl.h>    
#include <io.h> Required only for function declarations  

int _setmode ( int handle, int mode );

handle File handle  
mode New translation mode  

Remarks

The _setmode function sets to mode the translation mode of the file given by handle. The mode must be one of the following manifest constants:

Constant Meaning

_O_TEXT Sets text (translated) mode. Carriage-return–line-feed (CR-LF) combinations are translated into a single line-feed (LF) character on input. Line-feed characters are translated into CR-LF combinations on output.
_O_BINARY Sets binary (untranslated) mode. The above translations are suppressed.

The _setmode function is typically used to modify the default translation mode
of stdin, stdout, stderr, stdaux, and stdprn, but can be used on any file. If
_setmode is applied to the file handle for a stream, the _setmode function should be called before any input or output operations are performed on the stream.

Return Value

If successful, _setmode returns the previous translation mode. A return value of –1 indicates an error, and errno is set to one of the following values:

Value Meaning

EBADF Invalid file handle
EINVAL Invalid mode argument (neither _O_TEXT nor _O_BINARY )

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

_creat, fopen, _open

Example

/* SETMODE.C: This program uses _setmode to change stdin from text

* mode to binary mode.

*/

#include <stdio.h>

#include <fcntl.h>

#include <io.h>

void main( void )

{

int result;

/* 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" );

}

Output

'stdin' successfully changed to binary mode