다음을 통해 공유


_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.

If invalid parameters are passed to this function, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, this function returns –1 and sets errno to either EBADF, indicating an invalid file descriptor, or EINVAL, indicating an invalid mode argument (neither _O_TEXT nor _O_BINARY).

For more information about these and other return codes, see _doserrno, errno, _sys_errlist, and _sys_nerr.

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

_setmode

<io.h>

<fcntl.h>

For more compatibility information, see Compatibility in the Introduction.

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

'stdin' successfully changed to binary mode

.NET Framework Equivalent

See Also

Concepts

File Handling

_creat, _wcreat

fopen, _wfopen

_open, _wopen

_set_fmode