fdopen()

associate stream with file descriptor 

Function


SYNOPSIS

#include <stdio.h>

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


DESCRIPTION

The fdopen() function associates a stream with a file descriptor. File descriptors are obtained from open(), dup(), creat(), or pipe(), which open files but do not return pointers to a FILE structure stream. Streams are necessary input for almost all of the stdio library routines.

The type specified the stream must be allowed by the file access mode of the open file. The file position indicator associated with the new stream is set to the position indicated by the file offset associated with the file descriptor. The error indicator and end-of-file indicator for the stream are cleared.

When a file is opened for update, both input and output may be done on the resulting stream. However, output may not be directly followed by input without an intervening fflush(), fseek(), fsetpos(), or rewind(). Input may not be directly followed by output without an intervening fseek(), fsetpos(), or rewind(), or an input operation that encounters end-of-file.

When a file is opened for append, you cannot overwrite information already in the file. You can use fseek() to reposition the file pointer to any position in the file. However, when output is written to the file, the current file pointer is disregarded - in this case all output is written at the end of the file and causes the file pointer to be repositioned at the end of the output. If two separate processes open the same file for append, each process may write to the file without destroying output written by the other process. The output from the two processes is intermixed in the file in the order in which it is written.

When a stream is opened, it is fully buffered only if it does not refer to an interactive device.


PARAMETERS

fildes 

Indicates the file descriptor to map to a file pointer.

type 

Indicates a character string that specifies the desired type of file access. The first character of this string must be one of r (open for reading), w (open for writing), or a (open for writing at the end of file —append). After the first character, you can also add the + modifier that means to open for update, both reading and writing. The meaning of these flags is exactly as specified for fopen(), except that w and w+ do not cause truncation of the file.


RETURN VALUES

If successful, fdopen() returns a pointer to a stream. On failure, it returns a NULL pointer and errno is set to one of the following values:

EBADF 

The fildes argument is not a valid file descriptor.

EINVAL 

The value of the type argument is invalid.

EMFILE 

Too many file descriptors are open in the calling process.

ENOMEM 

Insufficient storage space is available.


CONFORMANCE

POSIX.1 (1996).


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
close(), creat(), dup(), fclose(), fopen(), freopen(), fseek(), open(), pipe(), write()


PTC MKS Toolkit 10.4 Documentation Build 39.