Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

fdopen - associate stream with file descriptor

&pagelevel(4)&pagelevel

Syntax

#include <stdio.h>

FILE *fdopen(int fildes, const char *mode); 

Description

Description fdopen() associates a stream with a file descriptor.

mode is a character string having one of the following values:

r or rb

open a file for reading

w or wb

open a file for writing

a or ab

open a file for writing at end of file

r+, r+b or rb+

open a file for update (reading and writing)

w+, w+b or wb+

open a file for update (reading and writing)

a+, a+b or ab+

open a file for update (reading and writing) at end-of-file.

The meaning of these flags is exactly as specified in fopen(), except that mode arguments
beginning with w do not cause the file to be truncated to length 0 (see fopen()).

The mode argument for the stream must only include the access modes that were originally
defined for the file, i.e. fdopen() cannot be used to change the file access mode. The
file position indicator associated with the stream is set to the same position as the file
position indicator associated with the file descriptor.

The error and end-of-file indicators for the stream are cleared. The fdopen() function may
cause the st_atime field of the underlying file to be marked for an update.

BS2000
The st_atime field is ignored for BS2000 files. The file retains its original access mode. (End)

For automatic conversion, the b for binary must not be specified in mode. Furthermore, the
environment variable IO_CONVERSION must not be present or must have the value YES. 

Return val.

Pointer to a stream



if successful.

 

Null pointer

if an error occurs; errno is set to indicate the error.

Errors

fdopen() will fail if: 

 

EBADF

fildes is not a valid file descriptor.

 

EINVAL

For POSIX files: mode is not a valid mode.

 

EMFILE

{FOPEN_MAX} streams are already open in the calling process.

{STREAM_MAX} streams are already open in the calling process.

 

ENOMEM

There is not enough memory to allocate a buffer.

 

BS2000

If errors occur, e.g. due to an invalid file descriptor, fdopen() will return neither a defined result nor an error message. The program does not abort in this case. (End) 

Notes

{STREAM_MAX} is the number of streams that one process can have open at one time. If defined, it has the same value as {FOPEN_MAX}, i.e. 2048.

File descriptors are obtained from calls like open(), dup(), creat() or pipe().

The program environment determines whether fdopen() is executed for a BS2000 or POSIX file. 

See also

fclose(), fopen(), open(), stdio.h, section “File processing”.