fdopen

Associates a stream with a file descriptor that represents an open file or device.

Library:LibC
Classification:POSIX
Service:File and Directory I/O

Syntax

  #include <stdio.h> 
   
  FILE *fdopen (
     int           fildes,
     const char   *mode);
  

Parameters

fildes

(IN) Specifies a file descriptor.

mode

(IN) Points to a string specifying the file open mode. See Standard File Open Modes.

Return Values

If successful, returns a pointer to the object controlling the stream. This pointer must be passed as a parameter to subsequent functions for performing operations on the file.

If the open operation fails, fdopen returns a NULL pointer and sets errno to one of the following:

Decimal

Constant

Description

4

EBADF

The file descriptor is not a valid.

5

ENOMEM

Insufficient space to allocate a buffer.

9

EINVAL

The mode argument is invalid.

11

EMFILE

The maximum number of streams are currently open in the calling process.

Remarks

The fdopen function associates a stream with a file descriptor, which represents an opened file or device. The fildes parameter is returned by a creat or open function. The mode parameter must match the mode with which the file or device was originally opened.

If mode does not match the flags used in opening the file originally, errno will be set to EINVAL and fdopen will fail. For a list of flags used by the oflag argument, see File Control Open Modes.

See Also