_setmode
Sets the file translation mode.
int _setmode ( int fd, int mode );
Parameters
- fd
- File descriptor.
- mode
- New translation mode.
Return Value
If successful, returns the previous translation mode. A return value of –1 indicates an error, in which case errno is set to either EBADF, indicating an invalid file descriptor, or EINVAL, indicating an invalid mode argument (neither _O_TEXT nor _O_BINARY).
See _doserrno, errno, _sys_errlist, and _sys_nerr for more information on these and other return codes.
Remarks
The _setmode function sets to mode the translation mode of the file given by fd. The mode must be one of two manifest constants, _O_TEXT or _O_BINARY. _O_TEXT sets text (translated) mode. Carriage return–line feed (CR-LF) combinations are translated into a single line feed character on input. Line feed characters are translated into CR-LF combinations on output. _O_BINARY sets binary (untranslated) mode, in which these translations are suppressed.
_setmode is typically used to modify the default translation mode of stdin and stdout, but you can use it on any file. If you apply _setmode to the file descriptor for a stream, call _setmode before performing any input or output operations on the stream.
Requirements
| Routine | Required header | Optional Headers | Compatibility |
|---|---|---|---|
| _setmode | <io.h> | <fcntl.h> | Win 98, Win Me, Win NT, Win 2000, Win XP |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Example
// crt_setmode.c
/* This program uses _setmode to change
* stdin from text mode to binary mode.
*/
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
int 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
See Also
File Handling Routines | _creat | fopen | _open | Run-Time Routines and .NET Framework Equivalents