Node:Descriptors and Streams, Next:Stream/Descriptor Precautions, Previous:File Position Primitive, Up:Low-Level I/O
Given an open file descriptor, you can create a stream for it with the
fdopen
function. You can get the underlying file descriptor for
an existing stream with the fileno
function. These functions are
declared in the header file stdio.h
.
FILE * fdopen (int filedes, const char *opentype) | Function |
The fdopen function returns a new stream for the file descriptor
filedes.
The opentype argument is interpreted in the same way as for the
The return value is the new stream. If the stream cannot be created (for example, if the modes for the file indicated by the file descriptor do not permit the access specified by the opentype argument), a null pointer is returned instead. In some other systems, |
For an example showing the use of the fdopen
function,
see Creating a Pipe.
int fileno (FILE *stream) | Function |
This function returns the file descriptor associated with the stream
stream. If an error is detected (for example, if the stream
is not valid) or if stream does not do I/O to a file,
fileno returns -1.
|
int fileno_unlocked (FILE *stream) | Function |
The fileno_unlocked function is equivalent to the fileno
function except that it does not implicitly lock the stream if the state
is FSETLOCKING_INTERNAL .
This function is a GNU extension. |
There are also symbolic constants defined in unistd.h
for the
file descriptors belonging to the standard streams stdin
,
stdout
, and stderr
; see Standard Streams.
STDIN_FILENO
0
, which is the file descriptor for
standard input.
STDOUT_FILENO
1
, which is the file descriptor for
standard output.
STDERR_FILENO
2
, which is the file descriptor for
standard error output.