setmode

Sets the mode of the file.

Library:LibC
Service:File and Directory I/O

Syntax

  #include <unistd.h> 
   
  int setmode (
     int   fildes, 
     int   oflag);
  

Parameters

fildes

(IN) Specifies a file descriptor.

oflag

(IN) Specifies the O_BINARY, the O_NDELAY flag, or a bitwise OR of these two flags. For a description of these flags, see File Control Open Modes.

Return Values

If successful, returns the previous mode that was set for the file. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

4

EBADF

Invalid file descriptor.

9

EINVAL

Invalid oflag parameter.

Remarks

The setmode function determines whether the file is treated as a binary file or as a text file:

  • If the O_BINARY flag is set in the oflag parameter, data is read or written unchanged.

  • If the O_BINARY flag is not set in the oflag parameter, data is read or written as text.

The mode of a file should not be changed after I/O has started. The mode should be changed after calling fdopen or fopen and before calling fwrite/write, fread/read, fseek/lseek, etc.

See Also