Add Book to My BookshelfPurchase This Book Online

Chapter 4 - The Standard I/O Library

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

File Pointers and File Descriptors
There are two functions provided for “translating” between file pointers and file descriptors:
    #include <stdio.h>
    int fileno(FILE *stream);
    FILE *fdopen(int fd, const char *type);
The fileno function returns the file descriptor associated with stream. This is useful for performing specialized I/O operations on files with which the Standard I/O Library is being used (these operations are described in later chapters).
The fdopen function allows a low-level file descriptor to be converted to a file pointer so that the library's buffering and formatting features can be used. The file descriptor is given in fd; type indicates how the stream should be opened. Note that type must match how the file descriptor was originally opened; for example, it won't work to specify a type of w if the file descriptor is only open for reading.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback