ffddooppeenn() -- STDIO Function (libc)

Open a stream for standard I/O
#iinncclluuddee <ssttddiioo.hh>
FFIILLEE *ffddooppeenn(_f_d, _t_y_p_e) iinntt _f_d; cchhaarr *_t_y_p_e;

ffddooppeenn() allocates  and returns a  FFIILLEE structure, or _s_t_r_e_a_m,  for the file
descriptor _f_d, as obtained from ooppeenn(), ccrreeaatt(), dduupp(), or ppiippee().  _t_y_p_e is
the manner in which you want _f_d to be opened, as follows:

    rr   Read a file
    ww   Write into a file
    aa   Append onto a file

_E_x_a_m_p_l_e
The following example obtains a  file descriptor with ooppeenn(), and then uses
ffddooppeenn() to build a pointer to the FFIILLEE structure.

#include <ctype.h>
#include <stdio.h>

void adios(message)
char *message;
{
    fprintf(stderr, "%s\n", message);
    exit(1);
}

main(argc, argv)
int argc; char *argv[];
{
    extern FILE *fdopen();
    FILE *fp;
    int fd;
    int holder;

    if (--argc != 1)
        adios("Usage: example filename");

    if ((fd = open(argv[1], 0)) == -1)
        adios("open failed.");
    if ((fp = fdopen(fd, "r")) == NULL)
        adios("fdopen failed.");

    while ((holder = fgetc(fp)) != EOF) {
        if ((holder > '\177') || (holder < ' '))
            switch(holder) {
            case '\t':
            case '\n':
                break;
            default:
                fprintf(stderr, "Seeing char %d\n", holder);
                exit(1);
            }
        fputc(holder, stdout);
    }
}

_S_e_e _A_l_s_o
ccrreeaatt(), dduupp(), ffooppeenn(), lliibbcc, ooppeenn()
POSIX Standard, section 8.2.2

_D_i_a_g_n_o_s_t_i_c_s
ffddooppeenn() returns  NULL if it cannot allocate  a FFIILLEE structure.  Currently,
only  20 FFIILLEE  structures can  be allocated  per program,  including ssttddiinn,
ssttddoouutt, and ssttddeerrrr.
